Solved

difference of mtime and ctime

Posted on 2011-09-14
5
423 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PowerShell Core for Advanced Linux Administrators

Understand advanced principals around Powershell Core with a focus on the Linux Administrator.  This course covers how to administer numerous environments across multiple platforms including Linux, Azure, AWS, and Google Cloud from a single shell instance.

Question has a verified solution.

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

rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
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.
Suggested Courses

631 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