Three important times in Linux

  

Three important times in Linux

First, definition

Chang time: referred to as ctime, the change time of a file or directory. In Linux, it is basically impossible to know the exact creation time of a file. The change time refers to the time when the attributes (owners, permissions, etc.) of the file or directory are modified. If a file needs to be backed up, the dump command needs to use ctime. You can use the ls-lc command to view ctime.

Access time: referred to as atime, the access time of a file or directory. It is the time when the data of a file was last accessed. For example, displaying the contents of a file or running a shell script will update the atime of the file. You can view it with the ls-lu command.

Modify time: referred to as mtime, the modification time of a file or directory. Is the time when the current content of the file is last modified, this is a time displayed in the long directory list

Second, how to modify

In Linux, the status command will be displayed three times,

For example: $cat file atime will be updated

$chmod g+w file ctime will be updated

$ echo “File contentss” > file file ctime And mtime will be updated.

Three time states for Linux files and directories:

1 mtime: Time when the file or directory was last modified

2 ctime: Last changed file or directory (change The time of the original data, ie the attribute, such as the time at which the inode node of the file was modified. And chmod, chown and other commands can also change this value.

3 atime: The time when the file or directory was last accessed.

For files, ctime must be changed when mtime is modified, because file size and so on are attributes. Some people say that atime will also change. To modify files, you must first access them. Actually, it is wrong, no access. The file can also be modified, such as #echo“Thos is a test”>>/etc/issue, the contents of the file will change, but the file is not accessed, so atime has not changed.

For a directory, access a directory with its atime change, mtime, and ctime. Modify a directory, touch a file in a directory, mtime and ctime will change, atime does not necessarily change.

Use the stat command to view three time values, such as stat filename. You can also use ls -l file to view file modification time, ls -lc file to view file status change time, and ls -lu file to view file access time. .

Copyright © Windows knowledge All Rights Reserved