Solved

difference of mtime and ctime

Posted on 2011-09-14
5
393 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Currently, there is not an RPM package available under the RHEL/Fedora/CentOS distributions that gives you a quick and easy way to allow PHP to interface with Oracle. As a result, I have included a set of instructions on how to do this with minimal …
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 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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now