Linking Files

Linux supports two types of links, which are ways to reference a single file by multiple names:

Hard Links This type of link creates two or more directory entries for each file. No directory entry is more "real" or "official" than the others, although one will necessarily be created first. If you delete any link, the others continue to work, until you delete the last link, at which point the file is deleted. All hard links to a file must reside on the same filesystem; you can't create, say, a hard link from your home directory to a file on a CD-ROM, floppy, or even another hard disk partition. Hard links between directories aren't permitted.

Symbolic Links This type of link, also known as a soft link, creates a special file whose contents point to another file by name. The soft link stops working if the original file is deleted, but the original file is unaffected if you delete any soft links pointing to it. You can create cross-filesystem soft links, as well as soft links to directories. Soft links impose an extra filesystem lookup and, therefore, are very slightly slower than hard links, although you won't notice this tiny difference in common operations.

You can create hard or soft links using the -I and -s options to cp, as noted in Table 5.2. You can also create links using the In command, which uses a syntax that's identical to that of cp. The two commands also share many options, including -b, -f, and -i. Ordinarily, In creates a hard link; but passing it the -s option causes it to create a symbolic link. In either case, you can create links on any Linux-native filesystem, such as the Mi nix filesystem, ext2fs, ext3fs, ReiserFS, JFS, orXFS. The Rock Ridge extensions to ISO-9660 also support soft links, although some mkisofs options cause them to be ignored or converted into duplicate files. A few non-Linux filesystems support soft links, such as OS/2's High-Performance File System (HPFS). The soft links are encoded as HPFS Extended Attributes and aren't useable from OS/2. You can't create links on most other filesystems, including FAT, although you can create soft links that reside on Linux filesystems that point to files on filesystems that don't support links.

Linux makes extensive use of links—especially symbolic links—in its standard system files. Many commands are available under multiple names via symbolic links, and symbolic links are also critical in most distributions' startup script systems. News server software typically makes heavy use of hard links.

Warning Some backup programs don't cope well with hard or symbolic links. The standard tar, for instance, handles symbolic links well, but it creates one file in its archive for each hard link. When restored, each file takes up its own share of disk space.

Top Sources For Free Backlinks

Top Sources For Free Backlinks

Discover a guaranteed method of building permanent backlinks from authority websites in your niche - FREE. Eliminate time consuming back-link tasks by downloading a free copy of this automated program and maximize your incoming links.

Get My Free Ebook

Post a comment