Access, Modify, and Change

29
Jun/09
0

What are Access, Modify, and Change as returned by the ’stat’ command?

What better way than to learn by example?  First, we start with no file:

rwill@rwill-laptop:~$ stat foo
stat: cannot stat `foo': No such file or directory
rwill@rwill-laptop:~$

Next we make our file:

rwill@rwill-laptop:~$ echo "Hello, World" > foo
rwill@rwill-laptop:~$ stat foo
 File: `foo'
 Size: 12            Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d    Inode: 246126      Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/   rwill)   Gid: ( 1000/   rwill)
Access: 2009-06-29 16:25:21.000000000 -0500
Modify: 2009-06-29 16:25:06.000000000 -0500
Change: 2009-06-29 16:25:06.000000000 -0500
rwill@rwill-laptop:~$

We can now see that our file exists and as expected, Access, Modify, and Change are all the same.  Now, lets read something from the file:

rwill@rwill-laptop:~$ stat foo
 File: `foo'
 Size: 12            Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d    Inode: 246126      Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/   rwill)   Gid: ( 1000/   rwill)
Access: 2009-06-29 16:25:21.000000000 -0500
Modify: 2009-06-29 16:25:06.000000000 -0500
Change: 2009-06-29 16:25:06.000000000 -0500
rwill@rwill-laptop:~$

We can now see that we Accessed the file (read from it) 15 seconds after it was created.  Now, let’s write to the file:

rwill@rwill-laptop:~$ echo "Hello Foo" >> foo
rwill@rwill-laptop:~$ stat foo
 File: `foo'
 Size: 22            Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d    Inode: 246126      Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/   rwill)   Gid: ( 1000/   rwill)
Access: 2009-06-29 16:27:05.000000000 -0500
Modify: 2009-06-29 16:27:05.000000000 -0500
Change: 2009-06-29 16:27:05.000000000 -0500
rwill@rwill-laptop:~$

Oh no! Everything changed.  Of course it did.  By writing to the file, it was Accessed, Modified, and Changed.  But don’t “Modify” and “Change” mean the same thing?  Not exactly.  A Modification is always a Change, but a Change is not necessarily a Modification.  Changes that are not Modifications include renaming, changing the permissions, etc:

rwill@rwill-laptop:~$ chmod 644 foo
rwill@rwill-laptop:~$ stat foo
 File: `foo'
 Size: 22            Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d    Inode: 246126      Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/   rwill)   Gid: ( 1000/   rwill)
Access: 2009-06-29 16:27:05.000000000 -0500
Modify: 2009-06-29 16:27:05.000000000 -0500
Change: 2009-06-29 16:28:26.000000000 -0500
rwill@rwill-laptop:~$ mv foo bar
rwill@rwill-laptop:~$ stat bar
 File: `bar'
 Size: 22            Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d    Inode: 246126      Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/   rwill)   Gid: ( 1000/   rwill)
Access: 2009-06-29 16:29:29.000000000 -0500
Modify: 2009-06-29 16:27:05.000000000 -0500
Change: 2009-06-29 16:29:28.000000000 -0500
rwill@rwill-laptop:~$

How about a homework assignment?  What happens when you move a file?

rwill@rwill-laptop:~$ mkdir baz
rwill@rwill-laptop:~$ mv bar baz
rwill@rwill-laptop:~$ stat baz/bar
 File: `baz/bar'
 Size: 22            Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d    Inode: 246126      Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/   rwill)   Gid: ( 1000/   rwill)
Access: 2009-06-29 16:29:29.000000000 -0500
Modify: 2009-06-29 16:27:05.000000000 -0500
Change: 2009-06-29 16:30:29.000000000 -0500
rwill@rwill-laptop:~$

That’s right.  A Change, but not a Modification.  It’s all so clear now, isn’t it?

Cheers –

Filed under: work
Comments (0) Trackbacks (0)

No comments yet.

Leave a comment

No trackbacks yet.