linuxdot.org Linux Expo Birmingham 2002
Linux news | Newbie's Linux manual | Linux links | Link us
The Linux columns | Book reviews
  DistroWatch + TuxReports November 2, 2002

Contents | Previous | Next | Download

Inodes and hard links

Representing a file with a filename, helps users better relate to it. A file though, is really indicated by an inode number. The same goes for each directory, which is just a special file storing the inode numbers to itself (.), its parent (..), the files it contains, and its subdirectories.

To view the inode numbers of a directory, enter:

ls -i   (or ls -ai to include hidden files)

To better understand inodes, enter the following two commands:

$ ls -id /usr
293761 /usr

$ ls -id /usr/bin/..
293761 /usr/bin/..

Notice how the .. directory and the usr directory share the same inode.

When you enter ls -l the second column displays the number of hard links. This being the number of files that point to the same inode.

A file will usually have just one hard link, whilst a directory has at least two (e.g. /bin and /bin/.). A directory with four hard links indicates it has two subdirectories, for example:

$ ls -ld /boot
drwxr-xr-x 4 root root 1024 Feb 4 14:48 /boot

4 is displayed because the following directories all point to the same inode:

/boot
/boot/.
/boot/grub/..
/boot/lost+found/..

Renaming a file or directory doesn't change its inode, and neither does moving it, so long as the file or directory is being moved to the same partition. Copying a file though would give the new file a new inode. (The same going for a directory and its content.)

None of this section you need to know at beginner level, but it does help better understand how things work.

Contents | Previous | Next | Download

About us  
Latest stable kernel: 2.4.19 | Latest development kernel: 2.5.44
Copyright © 1998-2002 Linuxdot.org.
Linux ® is a registered trademark of Linus Torvalds.