When you create a file, there is one hard link to it. You can then delete the file or, using Linux terminology, remove the link with the rm utility. When you remove the last hard link to a file, you can no longer access the information stored there and the operating system releases the space the file occupied on the disk for subsequent use by other files. This space is released even if symbolic links to the file remain. When there is more than one hard link to a file, you can remove a hard link and still access the file from any remaining link. Unlike DOS and Windows, Linux does not provide an easy way to undelete a file once you have removed it. A skilled hacker, however, can sometimes piece the file together with time and effort.
When you remove all hard links to a file, you will not be able to access the file through a symbolic link. In the following example, cat reports that the file total does not exist because it is a symbolic link to a file that has been removed:
-rw-r--r-- 1 alex pubs 981 May 24 11:05 sum $ ln -s sum total $ rm sum $ cat total cat: total: No such file or directory $ ls -l total
Irwxrwxrwx 1 alex pubs 6 May 24 11:09 total -> sum
When you remove a file, be sure to remove all symbolic links to it. Remove a symbolic link in the same way you remove other files:
$ rm total
Was this article helpful?