Linux file time detailed CTime mtime atime

Source: Internet
Author: User


Linux system files have three main time attributes, CTime (change times), Atime (Access Time), Mtime (Modify). These three time is easy to confuse, ready to learn more about Linux children's shoes please distinguish between the three


atime:access Time,Is the change when the file is read or executed, that is, the time the file was last read.
Description St_atime
time when file data is last accessed. Changed by the
Following Functions:creat (), Mknod (), pipe (),
Utime (2), and read (2).

mtime:modified Time,is when a file is written with changes to the contents of the file, which is the last time the file content has been modified.
Description St_mtime
Time when data is last modified. Changed by the fol-
Lowing functions:creat (), Mknod (), pipe (), utime (),
and write (2).

Ctime:change Time,is when you write a file, change the owner, permission, or link settings to change the contents of the Inode, that is, the time the file state was last changed.
Description St_ctime
time when file status is last changed. Changed by the
Following Functions:chmod (), Chown (), creat (),
Link (2), Mknod (), pipe (), unlink (2), Utime (), and
Write ().
Many people interpret it as create time, including many misleading books. In fact, CTime refers to change time.


Attention:
1, the change is the content of the text itself has changed (Mtime)
Change is the index node of the file has changed (CTime)
2. If you modify the contents of the file, update both CTime and Mtime
3, if only change the file index node, such as Modify permissions, it just changed the CTime

4, if the use of the Ext3 file system, the use of the Noatime parameter on Mount will not update the Atime information, that is, after accessing the file Atime will not be modified, and this does not represent the real situation


Tip: These three time stamp are placed in the inode. If the mtime,atime changes, the inode will be changed, the corresponding inode changed, that CTime also to be changed, the reason for using the noatime in the Mount option, is not want the file system to do too much modification, Thus improving read performance.



View the file's Atime, CTime, and Mtime.
# LS-LC filenameList the CTime of a file
# ls-lu filenameList the atime of a file
# ls-l filenameList the mtime of a file



Example
1:# echo "Hello World" >> myfile Atime unchanged, while changing the CTime and Mtime
2:# Cat MyFileCTime and mtime unchanged, only change atime
# ls MyFileCTime and Mtime and atime are not changing.
3:# chmod U+x myfileMtime and atime unchanged, only change CTime
4:# mv MyFile. /Mtime and atime unchanged, only change CTime


Other extensions:
Relatime Property

Starting with kernel2.6.29, a Relatime property is integrated by default. Using this feature to mount the file system, the Atime is updated only when Mtime is newer than atime.


Usage scenarios:
In a system where file reads are very frequent, the atime update is expensive, so use the Noatime property to stop updating atime when you mount the file system. But some programs need to be judged and manipulated according to Atime, and this time the Relatime feature comes in handy. In fact, this time atime and Mtime are already the same times, so you can understand that this option is to achieve compatibility with the Atime to launch, not a new time attribute.
How to use: # mount-o Relatime/dir# #挂载目录的时候加relatime参数


Linux file time detailed CTime mtime atime

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.