To find out how many hard links there are to a file, use the ls -l or l (long listing) command, as follows:
$ l -rw-r--r-- 1 johnd unixdoc 10586 Feb 25 12:26 1.start -rw-rw-r-- 2 johnd techpubs 61339 Feb 24 14:45 2.scosh -rw-rw-r-- 1 johnd techpubs 14741 Feb 25 11:18 3.dire -rw-rw-r-- 3 johnd techpubs 40419 Feb 25 15:57 4.filesYou need to locate all the links to a file or directory if you want to delete it: as long as there are links, you cannot delete the file or directory.
In a long listing, the number of links are shown in the second column from the left (after the sets of permissions). For example, in the above example, the file 4.files has three links to it.
You can find out where the common links to a single file are located, in two steps. First, you need to identify the inode number of the file (see ``How the system manages files and directories'' for information on inodes). To do this, use the ls -i option, as follows:
$ ls -i 20350 basking_shark 3886 cod 2002 halibut 3526 herring 10182 narwhalThe number before the filename is the file's inode number, for example, 2002 for the file called halibut.
To trace all the links to this file, you must find all the other files in the filesystem with this inode number. You can do this using the find -inum option, as follows:
$ find / -inum 2002 -print 2>/dev/null /u/dave/tmp/halibut /u/charles/fish6 /u/michael/project2/ichthyo14In this case, there are three files with the same inode number. In order to delete this file from the filesystem, it would be necessary to run rm on all the links.