Hard links and Unix file system nodes (inodes)

Suppose the root directory has inode number #2. Here is a small part of a Unix file system tree, showing hypothetical inode numbers of some directories and files:

 
inode #2
. (dot)
2
.. (dot dot)
2
home
123
bin
555
usr
654
   
   
 
inode #555
. (dot)
555
.. (dot dot)
2
rm
546
ls
984
cp
333
ln
333
mv
333
 
inode #123
. (dot)
123
.. (dot dot)
2
ian
111
stud0002
755
stud0001
883
stud0003
221
   

Note how one directory named bin (#555) has three name-to-number maps for the same node (#333).   All three names (cp, ln, mv) refer to the same node number, in this case a file containing an executable program.  (This program is one that looks at its name and behaves differently depending on which name you use to call it.)
 
inode #111
. (dot)
111
.. (dot dot)
123
.profile
334
.login
335
.logout
433
   
   
 
inode #333
Disk blocks

for the

cp / ln / mv

file

(link count: 3)

 
inode #335
Disk blocks

for the

.login

file

(link count: 1)

Note how the inodes for files contain disk blocks for the files and the inodes for directories contain only lists of names and inode numbers. The data for a file is not stored with the name of the file. The name is in the directory; the data is in the inode whose number appears with the name in the directory. When a directory is damaged on Unix, no file data is lost; only the names of the files are lost.