Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

difference of mtime and ctime

Posted on 2011-09-14
5
Medium Priority
?
444 Views
Last Modified: 2012-05-12
Though I understand the difference between ctime, mtime and atime. There is one scenario on which I am stuck and not able to get the answer.

I open a txt file and change just one character and then save it. It changed the mtime, ctime and atime.

I understand why did it change the atime and mtime but could not get the clue why ctime also needs to be changed.

AFAIK ctime should change if there is update in inode table and inode table does keep the size of the file and in this thing when I just replace a character the file size is same. so why there should be a ctime change. Please let me know to fix my understanding :-)
0
Comment
Question by:beer9
  • 3
5 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 36538706
ctime = last change time of file status (inode data / metadata)

mtime = last modification time of the file's contents.

wmp
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 1600 total points
ID: 36538748
Access time and modification time are recorded in the inode, so the inode always changes when one of the timestamps changes.

Inode structure:

struct dinode
{ ushort  di_mode;     /* mode and type of file   */
  short   di_nlink;    /* number of links to file */
  ushort  di_uid;      /* owner's user id         */
  ushort  di_gid;      /* owner's group id        */
  off_t   di_size;     /* number of bytes in file */
  char    di_addr[39]; /* disk block addresses    */
  char    di_gen;      /* file generation number  */
  time_t  di_atime;    /* time last accessed      */
  time_t  di_mtime;    /* time last modified      */
  time_t  di_ctime;    /* time created            */
};

http://140.120.7.20/LinuxKernel/LinuxKernel/node17.html

wmp
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 36538959
Note:

"time created" in the last line of course means the (re-)creation time of the inode (=ctime), NOT the file creation time!

wmp
0
 
LVL 12

Assisted Solution

by:Hugh Fraser
Hugh Fraser earned 400 total points
ID: 36555335
Using an editor (like vi) creates a new file when making a change, and hence a change in ctime. Instead of using an editor, try appending a character using

cat >>filename.txt
New text
<ctrl>d

If you look at the inode (ls -i filename.txt) you'll see it changes with vi, but not with cat.
0
 

Author Closing Comment

by:beer9
ID: 36575522
Thank you! :-)
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month13 days, 11 hours left to enroll

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question