Monday, October 24, 2005

(ln) - Symbolic / Soft Links and Physical / Hard Links

The ln command can create symbolic and physical links.
A physical or hard link is a pointer to data on the disk. In this respect, there can be multiple pointers to the same data. The link is the file name and the inode (term commonly used) is the location of the data.

freebsd01#ln basic.file hardlink.file

In the example above, any data added to hardlink.file or basic.file is written to the same inode location (data on the disk). if basic.file is delete, hardlink.file will still exist because only the link is deleted. Hardlinks share permissions. They cannot refer to directories.

A symbolic or soft link creates a file that has an underlying path to the original file. It is essentially a reference that can cross file systems and point to directories.

freebsd01#ln -s basic.file softlink.file

Any opens, reads, and writes to softlink.file are passed to basic.file. Similarly, if basic.file is deleted, softlink.file will not work.

Finally, use the command ln -l to see what name a file is linked to.

Here are some very good explanations of hard links and soft links:
Wikipedia - Hard Link
Wikipedia - Symlink
Linux Gazette

0 Comments:

Post a Comment

<< Home