Solved

difference of mtime and ctime

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSL/TLS - openssl troubleshooting 3 80
Linux MD5 Hash 7 97
comm diff cmp unix commands 2 19
Issue when using 'yum update' 4 23
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…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

738 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