In many cases, you may find yourself needing a particular file or directory in one location while it is actually stored in another. One solution to this in Linux and Unix operating systems is linking. There are two types of links: hard links and symbolic links.
Hard links are always associated with a specific piece of data at a specific location. Even if moved or removed, a hard link still links to it but cannot cross system boundaries or link directories. Symbolic links refer to the abstract location of a file. If the file is moved or removed, the symbolic link essentially no longer exists. It can, however, cross file system boundaries and link directories.
To make a hard link, simply run the “ln” command without options:
# ln /filesystem/file /filesystem/file2
To make a symbolic link, use the “-s” option:
$ ln -s /filesystem/file /filesystem/file2
In most Linux shells, depending on the configuration, symbolic links will appear as a different color than normal files, often a light blue. This lets you know that it actually points to another file. If you list in long form with “ls -al”, you will see indications of where links point. For example:
lrwxrwxrwx 1 root root 19 Nov 15 2013 libstdc++.so.6 -> libstdc++.so.6.0.18
This means that libstdc++.so.6 is actually a symbolic link for libstdc++.so.6.0.18.
Hard and symbolic links are a quick and easy way to make sure programs and services can access files the way they need them, and it is built into most Linux file systems.