*NIX has two kinds of links: hard and soft. link creates a hard link, in which two separate directory entries point to the same inode on the disk (which also increments the link count on that inode). symlink creates a soft (or symbolic) link in which the directory entry contains the name of the target file.
Hard links are separate, redundant entries in the filesystem. When you unlink one of them, the other still points to the file (although the inode's link count is decremented) so the contents on disk are not removed; once you unlink all directory entries pointing to the inode in question it will be put back on the free list and made available for reuse. You can detect a hard link by using the -i option to ls to show the inode number in listings; two directory entries hardlinked to the same file show the same inode number.
Symbolic links are more like pointers by name to real files. Removing a symlink just removes the pointer entry in the directory. Removing the target leaves the pointer dangling and trying to access through it will fail.
Update: Here's an example which may clarify hard links.
$ touch file1 $ ls -li file1 4210927 -rw-r--r-- 1 fletch wheel 0 Dec 8 11:15 file1 $ perl -e 'link( "file1" => "file2" ) or die "$!"' $ ls -li total 0 4210927 -rw-r--r-- 2 fletch wheel 0 Dec 8 11:15 file1 4210927 -rw-r--r-- 2 fletch wheel 0 Dec 8 11:15 file2 $ echo "Through file2" >> file2 $ ls -li total 16 4210927 -rw-r--r-- 2 fletch wheel 14 Dec 8 11:15 file1 4210927 -rw-r--r-- 2 fletch wheel 14 Dec 8 11:15 file2 $ cat file1 Through file2 $ rm file1 $ cat file2 Through file2 $ ls -li total 8 4210927 -rw-r--r-- 1 fletch wheel 14 Dec 8 11:15 file2
Update: Minor wording change to try and make it clear that its the link count that's a property of the inode itself that gets decremented.
In reply to Re^2: (OT) Is there any difference "link" and "copy" functions
by Fletch
in thread (OT) Is there any difference "link" and "copy" functions
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |