The !SPAN>ln command lets a file on your disk be accessed with more than one file name by !SPAN> hard-linking a new file name to it. When you hard-link a file, you create a new file name and connect it with the original file. Hard-linking can let two users share the same file or provide a more convenient way of referencing files buried deep in a series of directories. !SPAN>
Here's an example. Suppose hermie and sigmund are working on the Top Secret Snowgun Project, and the formula for the Snowgun is stored in !SPAN>/home/hermie/projects/snowgun/formula.txt. Sigmund doesn't want to type that long, ugly file name every time he needs to update the file, so he creates a hard link to the file, like this:!SPAN>
ln /home/hermie/projects/snowgun/formula.txt sgformula!SPAN>
The preceding command links the file name !SPAN>sgformula to the file !SPAN>formula.txt contained at the end of that directory string. There's still only one copy of the snowgun formula (!SPAN>formula.txt) on the disk, but now sigmund can access it quickly with the name !SPAN>sgformula (assuming hermie gives him write permission to the file). Interestingly, if hermie deletes his !SPAN>projects/snowgun/formula.txt file, Linux will not remove the file from the file system because sigmund still has a link to it.!SPAN>
Think of the !SPAN>ln command as a way of creating a kind of nickname for a file. By the way, ther e is no parallel to this file linking concept in the DOS world--you'd have to create a second copy of the file and keep the various copies in synch manually to get a similar result.!SPAN>
Creating a Symbolic Link!SPAN>
The type of link we just created is called a hard link. There's another type called a !SPAN>symbolic !SP AN>link. Symbolic!SPAN> links!SPAN> (also called !SPAN>symlinks) work like hard links, but you can do a bit more with them. If you want to create a link to a directory (as opposed to a file), you must create a symlink. Symlinks are also required when linking to a file on a different disk partition or on a network. !SPAN>
To create a symbolic link, add the !SPAN>-s parameter to the !SPAN>ln command, like this:!SPAN>
ln -s /dev/fd0 A: !SPAN>
!SPAN>ln -s /etc/httpd/conf web !SPAN>
The first example allows you to access the floppy drive as drive A, just like in DOS, and the second creates a directory entry called !SPAN>web that can be used instead of !SPAN>/etc/httpd/conf.!SPAN>
Previous Lesson: Task Scheduling
Next Lesson: The Vi Editor
|
![]() |
|
| <Send This Link to a Friend> <Help> <Bookmark This Page> | ||