Solved

difference of mtime and ctime

Posted on 2011-09-14
5
401 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 400 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:hfraser
hfraser earned 100 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

832 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