What is an inode?

  • Lets start with this.
  • The filesystem is made up of inodes.
  • Inodes contains metadata about a file.
    • size
    • dev id
    • UID, GID
    • OTher stuff
    • DOES NOT STORE FILENAME.

Viewing inodes

  • df -i will show us how many inodes we have and how many available to us.
  • Can we have more files than inodes?
  • ls doesn't access inode metadata, but ls -l does.
    • ls -i will give us information about inode
  • stat f1.txt will give us metadeta information.

More testing with inodes

  • Examine inodes when:
    • we create a symbolic link?
    • we create a hard link?
  • So, files can have multiple names.

Other inode implications

  • An inode may have no links
  • A files inode number stays the same when moved to another directory on the same device.
  • root generally has an inode of 2? (ls -lai /)

More Inode stuff

Where is the NAME of the file. Or the Path? It's NOT in the inode. It's NOT in the data blocks. It's in the directory. That's right. A "file" is really in three (or more) places on the disk.

You see, the directory is just a table that contains the filenames in the directory, and the matching inode. Think of it as a table, and the first two entries are always "." and ".." The first points to the inode of the current directory, and the second points to the inode of the parent directory.

One more piece of information

When you create a hard link, it just created a new name in the table, along with the inode, without moving the file. When you move a file (or rename it), you don't copy the data. That would be Slow. You just create the (name,inode) entry in a new directory, and delete the old entry in the table inside the old directory entry. In other words, moving a gigabyte file takes very little time. In the same way, you can move/rename directories very easily. That's why "mv /usr /Old_usr" is so fast, even though "/usr" may contain (for example) 57981 files.

Inode Examples

  • Create a dir and cd into it
    • What does output of ls -id . show?
    • cd back to parent directory and ls -id testdir, should show same inode number
  • Now do an ls -la on that directory. What is the field after the permissions? This is count of hard links to the file.
    • We should see that there are (2) hard links, one for filename and one for ..

Inode Examples

  • Look at this output:

      drwxrwxr-x  6 joe  joe        4096 Oct  6 10:15 it1100
      drwxrwxr-x 41 joe  joe        4096 Oct 22 11:22 lab6
    
  • What does the 41 mean on line 2?

  • Create a dir (look at that column), create subdir (look), create sub,subdir(look)

Finding with inodes.

  • find / -inum 147649