Thread: difference between st_atime, st_mtime and st_ctime

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    9

    difference between st_atime, st_mtime and st_ctime

    Hi there,

    I m just wondering if someone could explain me the difference between these three timestamps. All I know is that

    st_atime: time of last access
    st_mtime: time of last data modification
    st_ctime: time of last file status change

    Well, for me, last access time is clear that should be the time the file is opened the last time, right? But the last two ones? What happens if I copy or rename a file, what changes? Or what happens when I resize a picture?

    Thanks
    TurboToJo

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    mtime is when you open the file for "w" or "a"
    ctime is when you do chmod(), and a few other things which I can't remember without RTFM
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    See this.
    My understanding was ctime dealt with changes to the inode, but according to the URL I posted it also gets updated with file content changes.

    EDIT: Experimented...
    ctime does change when file contents change. Make a test file, change its name, contents etc, and watch how the times change. You can view them easily with the "stat" command. (ie, "stat testfile.txt")
    Last edited by Cactus_Hugger; 07-21-2007 at 12:52 AM.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

Popular pages Recent additions subscribe to a feed