Meanings of Access,Modify and Change in stat command

I keep forgetting the “subtle” differences between access,modify and change attributes of an inode. I will try to take some note here for you and me. My file test.txt has got the text “abc” in it which is 3 bytes + 1 new line = 4 bytes and I pasted inode information below via stat command.

$ stat test.txt
  File: `test.txt'
  Size: 4               Blocks: 8          IO Block: 4096   regular file
Device: fd1ch/64796d    Inode: 1114186     Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 333/genc)   Gid: ( 333/genc)
Access: 2012-05-08 14:46:11.000000000 +0200
Modify: 2012-05-08 14:46:11.000000000 +0200
Change: 2012-05-08 14:46:11.000000000 +0200

As it can be seen, file has 4 bytes and access,modify and change attributes are set to the same time stamp. Lets display the file via “cat test.txt” and look at the new stats.

$ stat test.txt
  File: `test.txt'
  Size: 4               Blocks: 8          IO Block: 4096   regular file
Device: fd1ch/64796d    Inode: 1114186     Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 333/genc)   Gid: ( 333/genc)
Access: 2012-05-08 14:49:37.000000000 +0200
Modify: 2012-05-08 14:46:11.000000000 +0200
Change: 2012-05-08 14:46:11.000000000 +0200

Hmm, only access attribute changed as we didn’t modify the file. Let’s add a single character e.g “d” and save the file and see the stat.

$ stat test.txt
  File: `test.txt'
  Size: 5               Blocks: 8          IO Block: 4096   regular file
Device: fd1ch/64796d    Inode: 1114187     Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 333/genc)   Gid: ( 333/genc)
Access: 2012-05-08 15:06:09.000000000 +0200
Modify: 2012-05-08 15:06:09.000000000 +0200
Change: 2012-05-08 15:06:09.000000000 +0200

As you can see size is now 5 bytes and all attributes are updated – access,modify,change
Here is the thing. Access and modify are updated along with change why? Indeed if you modify the file, both change and modify values will be updated. Then I ask myself why do I need change attribute then? Indeed if you update anything in inode, only change attribute will be updated. Lets modify file permission to 755 i.e update the inode and see how it will affect the stat output;

$ chmod 755 test.txt
$ stat test.txt
  File: `test.txt'
  Size: 5               Blocks: 8          IO Block: 4096   regular file
Device: fd1ch/64796d    Inode: 1114186     Links: 1
Access: (0755/-rwxr-xr-x)  Uid: ( 333/genc)   Gid: ( 333/genc)
Access: 2012-05-08 15:06:09.000000000 +0200
Modify: 2012-05-08 15:06:09.000000000 +0200
Change: 2012-05-08 15:14:00.000000000 +0200

Bingo! only “Change” is updated. I hope I won’t forget these after posting this article:)

About: rtoodtoo

Worked for more than 10 years as a Network/Support Engineer and also interested in Python, Linux, Security and SD-WAN, currently living in the Netherlands and works as a Network Support Engineer. // JNCIE-SEC #223 / RHCE / PCNSE


You have a feedback?

This site uses Akismet to reduce spam. Learn how your comment data is processed.