Home  >  Article  >  Operation and Maintenance  >  What types of file times are there in Linux?

What types of file times are there in Linux?

青灯夜游
青灯夜游Original
2023-02-07 13:58:071733browse

Linux has three types of file times: 1. Access time (atime). If a file is read once, its access time will change; 2. Modification time (mtime), which refers to the last time the file content was modified. Modification time; 3. Status change time (ctime), when the status of the file is changed, the status time will change accordingly.

What types of file times are there in Linux?

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

In Linux, the time of a file is an important attribute of the file. There are three main times of the file in Linux, namely modification time, access time and status time:

  • Access time(atime: access time): Read the content of the file once, and atime will be updated. For example, use more, cat and other commands on this file. In addition, the ls and stat commands will not modify the access time of the file.

  • Modification time(mtime:modifiy time):mtime is the time when the file content was last modified. For example, save the file after vi. The time listed by ls -l is this time.

  • State change time(ctime: change time): ctime changes with the content of the i node when writing a file, changing owner, permissions or link settings What changes is the time when the i node of the file was last modified. If the file attributes are modified once through the chmod and chown commands, this time will be updated.

Attribute description

File time attribute Description Description
mtime Modification time The time when the file content was last modified, we often use The file time displayed by the ls -l command is this time. When the file content is modified, its mtime will change accordingly.
atime Access time When a read operation is performed on a file, its access time will change. For example, cat, more and other operations, but the stat and ls commands will not affect atime.
ctime State time When the status of the file is changed, the status time will change accordingly. For example, when using chmod, chown, etc. to change file attributes, the ctime of the file will be changed.

Check the file time

Generally, according to the time attribute of the file, you can combine it with the find command to query the desired results

For example, query files updated within the last 2 hoursfind / -mtime -2

How to view Linux file attributes:

  • ls -lc filename List the ctime (last status change time) of the file

  • ls -lu filename List the atime (last status change time) of the file Access time)

  • ls -l filename List the mtime (last modification time) of the file

  • stat filename See the three time attributes of the file at once

Create a new fileWhen touching file, ctime, atime, and mtime are the same; when After using vi to write information to a file, you must first access the file, so atime changes. When the file content changes, all ctime and mtime also change; ctime will change when using the chmod command.

What types of file times are there in Linux?

General operations that affect the three time attributes:

  • cat, less, more, etc. only access files and do not modify them. File operations will only modify the value of atime.

  • The operations of chmod and chown to modify file permissions, owners, and groups will modify the values ​​of atime and ctime.

  • vi and other operations that modify the file content will modify the values ​​of atime, ctime, and mtime.

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of What types of file times are there in Linux?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn