Jump to Navigation

219 - File and directory timestamps in Linux System

Linux keeps 3 timestamps for each file: mtime, ctime, and atime. Most people seem to understand atime (access time), it is when the file was last read.
There does seem to be some confusion between mtime and ctime though. ctime is the inode change time while mtime is the file modification time. "Change"
and "modification" are pretty much synonymous. mtime changes when you write to the file. It is the age of the data in the file. Whenever mtime changes,
so does ctime. But ctime changes a few extra times. ( For example, it will change if you change the owner or the permissions on the file.)

Three times tracked for each file in Unix are these :

  • Access time - atime

Access time shows the last time the data from a file was accessed ? read by one of the Unix processes directly or
through commands and scripts.

  • Change time - ctime

ctime also changes when you change file's ownership or access permissions.
It will also naturally highlight the last time file had its contents updated.

  • Modify time - mtime

Last modification time shows time of the  last change to file's contents. It does not change with owner or permission changes,
and is therefore used for tracking the actual changes to data of the file itself.

Show atime, ctime and mtime with stat command :

[root@myserv ~]# stat install.log
  File: `install.log'
  Size: 53592           Blocks: 128        IO Block: 4096   regular file
Device: fd00h/64768d    Inode: 186613762   Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2012-03-16 01:43:53.000000000 -0700
Modify: 2009-06-01 18:51:55.000000000 -0700
Change: 2009-06-01 18:51:59.000000000 -0700

Suppose your restore program did not restore the mtime. You don't want your program to print today's date. mtime is under your control.
You can set it to what ever you want. So just do :

# touch -t 201203121800 yourfile.txt

ls command :

# ls -ltr          (mtime)
# ls -lutr        (atime)
# ls -lctr         (ctime)

 



Main menu 2

Story | by Dr. Radut