When you change permissions on a file, the file contents aren't affected. The change is made to the i-node.
So what's an inode?
A quick visit to Wikipedia explains:
All of that file "header" information is known as metadata. Here's how it is explained by the whitepaper, Inproving Database Performance with the AIX Concurrent I/O. My emphases in bold and my comments are in red.
2.2 Inode LockingEnd of quotation.
While an application views a file as a contiguous stream of data, this is not actually how a file is stored on disk. In reality, a file is stored as a set of (possibly non-contiguous) blocks of data on disk. Each file has a data structure associated with it, called an inode.
The inode contains all the information necessary for a process to access the file, such as file ownership, access rights, file size, time of last access or modification, and the location of the file’s data on disk. Since a file’s data is spread across disk blocks, the inode contains a “table of contents” to help locate this data. Good analogy.
It is important to note the distinction between changing the contents of an inode and changing the contents of a file. The contents of a file only change on a write operation. In other words, when you write something to the file. That means copying, appending, editing and saving, or even overwriting the file.
The contents of an inode change when(1) the contents of the corresponding file change (because when you update the file contents, you change the time of last modification. This is what you can search for with the find command using the -mtime flag, but I digress), or
(2) when its owner (e.g. using chown), permissions (chmod or chgrp), or any of the other information that is maintained as part of the inode changes.
Thus, changing the contents of a file automatically implies a change to the inode, whereas a change to the inode does not imply that the contents of the file have changed.
You can see a lot of the inode (metadata) information using the ls -l command:
And you can have a look at the inode in more detail with the AIX istat command:
ls -l .profile
-rwxr----- 1 janedoe staff 254 May 24 23:10 .profile
Last updated and Last modified
Inode 13 on device 10/8 File
Owner: 205(janedoe) Group: 1(staff)
Link count: 1 Length 254 bytes
Last updated: Tue Jun 7 12:24:03 EST 2011
Last modified: Tue May 24 23:10:31 EST 2011
Last accessed: Tue May 24 23:10:31 EST 2011
There are two fields on the istat command you might be wondering about: Last updated and Last modified.
Last updated shows the date and time of the last i-node update.
Last modified shows the date and time of the last file modification, in other words, the file contents.
A perm change
Now, supposing I change the group from staff to mail:
You can see the new group is mail. Notice that the date and time stamp in ls -l hasn't changed, because I didn't modify the file contents. The change to the group access has only changed the metadata.
chgrp mail .profile
# ls -l .profile
-rwxr----- 1 janedoe mail 254 May 24 23:10 .profile
So now, let's update the file contents and see the result:
Quick edit of file, using our AIX Down Under advanced typing skills. [Time for you to have a coffee ... ]
[... several minutes later ... ]
OK welcome back
I added a single character to the file, so the file size has changed from 254 to 255 bytes. The ls -l shows the file modification time has been updated.
ls -la .profile
-rwxr----- 1 janedoe mail 255 Jun 07 12:36 .profile
Both of those changes will be shown on the istat command output:
istat .profileFun with inum
Inode 13 on device 10/8 File
Owner: 205(janedoe) Group: 6(mail)
Link count: 1 Length 255 bytes
Last updated: Tue Jun 7 12:36:29 EST 2011
Last modified: Tue Jun 7 12:36:29 EST 2011
Last accessed: Tue Jun 7 12:36:23 EST 2011
If you want to list the inode number for a file, you can use the istat command, or simply add the -i flag to your ls -l command:
The inode number is 13 (not a lucky number for Unix people, because it usually indicates a permissions problem. Not this time, though).
ls -li .profile
13 -rwxr----- 1 janedoe mail 255 Jun 07 12:36 .profile
You can find a file by its inode number:
find . -inum 13This can be helpful if you have a file with strange characters for its name. You can delete or rename the file by identifying it by its inode number.
The inode number is unique withing a file system. So if you started this find command from a directory which contains several file systems underneath it, you might find several files.
There are other things worth knowing about the inode, especially some of the options for the find command:
-atime to search by access timeThere are some options for the find command to search by file modification time, access time etc. in minutes:
-mtime for modification time
# List all files modified in the last 5 days
find . -mtime 5 -ls
-user to identify the owner of the file (and why didn't they make this to -owner?)
-mmin nYou get the idea. See the find command documentation for more details.
It's helpful to know about inodes. It can help you understand Concurrent I/O (cio) which you may set as a mount option on some database file systems. Have a read of the relevant section from the Improving Database Performance with the AIX Concurrent I/O whitepaper. It also gives a good explanation of inode locking.
Many sys admins go through their lives without knowing what an inode is. Using ls -l (with their favourite flags - everybody's got their own) was enough to carry them through. But if you do need to do a search for files by something other than their names, having a grasp of what inodes are about is a help. Thanks to that whitepaper on Concurrent I/O and some handy command documentation, when someone starts to give you an unsolicited lecture about inodes, you'll be able to tell them "I know dat."