Website based on my experience working as System Administrator

LINUX INFORMATION WEBSITE

This site is dedicated to providing tutorials, help, guides and links for Linux users.
HOME PAGE
LINUX COMMANDS
   
   
   
   
   
   
   
   
   

LINUX COMMANDS

Contents | Previous | Next

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

 
Last Update: Jan 2003

HOME | CONTACT | FAQ'S | TRICKS & TIPS | WEIRD NEWS
This Material has been taken from different sources. Its free for anyone to use and reproduce.