Saturday, February 4, 2012

Timestamps associated with every file/directory in Unix/Linux filesystem


There are three timstamps associated with every file(or directory) in Unix/Linux  filesystem

  • Access Time(atime) - The last time the file (or directory) data was accessed(read the file's contents)
  • Modification Time(mtime) - The last time the file (or directory) data was modified(written or created)
  • Change Time(ctime) - The last time the inode status was changed(modify the file data or its attributes)
Using stat command we can get to know the all the three timestamps

$ stat bookmarks.html
Access: 2011-10-30 21:11:00.787309030 +0530
Modify: 2011-10-02 19:22:08.660739370 +0530
Change: 2011-10-02 19:22:08.660739370 +0530

Scenario 1: Just access the file
$ less bookmarks.html

$ stat bookmarks.html
Access: 2011-10-30 21:11:00.787309030 +0530
Modify: 2011-10-02 19:22:08.660739370 +0530
Change: 2011-10-02 19:22:08.660739370 +0530

We can see that atime is modified above

Scenario 2:Change contents of the file
Let us modify the file bookmarks.html
$ vi bookmarks.html

$ stat bookmarks.html
Access: 2012-02-05 00:09:16.690477352 +0530
Modify: 2011-10-02 19:22:08.660739370 +0530
Change: 2011-10-02 19:22:08.660739370 +0530

We can now see that all three timestamps - atime,mtime and ctime are changed

Scenario 3: Change the attributes of a file
Let us change the file attributes
$ chmod 644 bookmarks.html

$ stat bookmarks.html
Access: 2012-02-05 00:11:06.814915133 +0530
Modify: 2012-02-05 00:11:06.814915133 +0530
Change: 2012-02-05 00:24:20.619104936 +0530

We can see that ctime alone is modified now

Time of last file modification(mtime): ls -l
Time of last access(atime): ls -lu
Time of last inode modification(ctime): ls -lc 
Note about atime


If atime updates are enabled by default in Linux/Unix file systems, then every time a file is read, its inode needs to be updated. These atime updates can require a significant amount of unnecessary write traffic and file-locking traffic. That traffic can degrade performance; therefore, it may be preferable to turn off atime updates. So, while mounting the filesystem, specify the option noatime  in /etc/fstab or in mount command.


No comments:

Post a Comment