In Linux, you can use the ln (link) command to make links to a file or directory. A file can have any number of so-called "hard" links to it. Effectively, these are alternative names for the file. So if you create a file called afile, and make a link to it called bfile, there are now two names for the same file. If you edit afile, the changes you've made will be in bfile. But if you delete afile, bfile will still exist; it disappears only when there are no links left to it. Hard links can be made only on the same filesystem — you can't create a hard link to a file on another partition because the link operates at the filesystem level, referring to the actual filesystem data structure that holds information about the file. You can create a hard link only to a file, not to a directory.
You can also create a symbolic link to a file. A symbolic link is a special kind of file that redirects any usage of the link to the original file. This is somewhat similar to the use of "shortcuts" in Windows. You can also create symbolic links to directories, which can be very useful if you frequently use a subdirectory that is hidden several levels deep below your home directory. In the last example in the list that follows, you will end up with a symbolic link called useful in the current directory. Thus, the command cd useful will have the same effect as cd docs/ linux/suse/useful.
■ ln afile bfile: Makes a "hard" link to afile called bfile
Was this article helpful?