Linux File Time Explanation ctime mtime atime, mtimeatime
Linux system files have three main time attributes: ctime (change time), atime (access time), and mtime (modify time ). These three times are very confusing. Be sure to distinguish them from linux kids shoes.
Atime: Access time, which is changed when the file is read or executed, that is, the last time the file was read.
Note: st_atime
Time when file data was last accessed. Changed by
Following functions: creat (), mknod (), pipe (),
Utime (2), and read (2 ).
Mtime: Modified time, which is the last modification time when the file content is changed when the file content is written.
Note: st_mtime
Time when data was last modified. Changed by the fol-
Lowing functions: creat (), mknod (), pipe (), utime (),
And write (2 ).
Ctime: Change time, which is the last time when the file status is changed as Inode content changes when the file is written, the owner, permission, or link settings are changed.
Note: st_ctime
Time when file status was last changed. Changed by
Following functions: chmod (), chown (), creat (),
Link (2), mknod (), pipe (), unlink (2), utime (), and
Write ().
Many people regard it as create time, including many misleading books. In fact, ctime refers to change time.
Note:
1. Modify the text content (mtime)
The change is because the index node of the file has changed (ctime)
2. If the file content is modified, both ctime and mtime are updated.
3. If only the file index node is changed, such as the permission modification, the ctime is changed.
4. If the noatime parameter is used during mount when the ext3 file system is used, the atime information will not be updated. That is, atime will not be modified after the file is accessed, but this does not represent the actual situation.
TIPS: these three time stamps are all stored in inode. If mtime and atime are modified, inode will be changed. If the corresponding inode is changed, the ctime will be changed. The reason why noatime is used in the mount option, I just don't want to modify the file system too much to improve the reading performance.
View the atime, ctime, and mtime of the file.
# Ls-lc filename: list the ctime of a file
# Ls-lu filename: list the atime of a file
# Ls-l filename: list the mtime of a file
Example
1: # echo "Hello World"> myfile atime remains unchanged, and ctime and mtime are modified at the same time.
2: # cat myfile ctime and mtime remain unchanged. Only atime is changed.
# Ls myfile ctime, mtime, and atime remain unchanged
3: # chmod u + x myfile mtime and atime remain unchanged, only ctime is changed
4: # mv myfile ../mtime and atime remain unchanged, only ctime is changed
Other extensions:
Relatime attributes
From kernel2.6.29, A relatime attribute is integrated by default. After you use this feature to mount a file system, atime is updated only when mtime is more than atime.
Use Cases:
In systems with frequent File Read operations, atime updates impose a high overhead. Therefore, when mounting a file system, the noatime attribute is used to stop updating atime. However, some programs need to make some judgments and Operations Based on atime. At this time, the relatime feature will come in handy. In fact, at this time, atime and mtime are already the same time. Therefore, we can understand that this option is only available for compatibility with atime and is not a new time attribute.
Usage: # mount-o relatime/dir # Add the relatime parameter when mounting the Directory