Linux file time detailed CTime, Mtime, atime "Turn"

Source: Internet
Author: User

This article was reproduced from: http://blog.csdn.net/doiido/article/details/43792561

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, which is changed when the file is read or executed, that is, when 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, which is changed when a file is written with changes to the contents of the file, refers to when the file content was last 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 changed as the content of the Inode changes when writing to a file, changing owner, permission, or link settings, that is, when the state of the file 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, then the CTime will be changed, the reason for the use of noatime in Mount option, is not do not want the file system to do too much modification, thereby improving read performance.



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



Example
1: # echo "Hello World" >> myfile atime unchanged, while changing CTime and Mtime
2: # Cat myfile CTime and mtime unchanged, change only atime
# ls myfile CTime and mtime and atime are not changed
3: # chmod u+x myfile Mtime 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 "Turn"

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.