Make links between files. Files/directories located somewhere in the filesystem can be accessed in another location as if they are located in the stated location.
[yuni@lovely-linux yuni]$ ls -l /usr/tmp/* ls: /tmp/xxx/*: No such file or directory [yuni@lovely-linux yuni]$ ls -l /var/tmp/* ls: /tmp/xxx/*: No such file or directory
Nothing inside both directories.
[yuni@lovely-linux yuni]$ cat - > /usr/tmp/test_linking Testing, testing, testing... ^D [yuni@lovely-linux yuni]$ ls -ld /usr/tmp/* -rw------- 1 yuni yuni 29 Jul 13 13:30 /usr/tmp/test_linking
The file test_linking created in /usr/tmp with file size 29 bytes.
[yuni@lovely-linux yuni]$ ls -ld /var/tmp/* -rw------- 1 yuni yuni 29 Jul 13 13:30 /var/tmp/test_linking
The same file exists in /var/tmp too!!
[yuni@lovely-linux yuni]$ ls -l /usr/tmp lrwxrwxrwx 1 root root 10 Feb 6 19:06 /usr/tmp -> ../var/tmp/
Because /usr/tmp is not a real directory. It is simply a symbolic link to /usr/var/tmp, i.e., /var/tmp.
There are two kinds of links: symbolic link and hard link.
A "hard link" is another name for an existing file. The link and the original file are indistinguishable. By judging on the files involved in the link, you cannot tell which is the original file and which is the link. Hard link cannot be made on directory nor made across filesystems.
"Symbolic links" ("symlinks" for short) are a special file type in which the link file actually refers to a different file, by name. When most operations (opening, reading, writing, and so on) are passed the symbolic link file, the system automatically "dereferences" the link and operates on the target of the link. But some operations (e.g., removing) work on the link file itself, rather than on its target.
To create symbolic link,
ln -s <target file or directory> <link name>
To create hard link,
ln <target file or directory> <link name>
ln -s ~/archive/homework_backup ./homework_final
ln ~/archive/homework_backup/file_2 ./file_2
ls -l . ~/archive/homework_backup/file_2
-rw------- 2 yuni yuni 48 Jul 15 16:16 /home/yuni/archive/homework_backup/file_2 .: total 29 drwx------ 2 yuni yuni 512 Jul 15 16:40 ./ drwx--x--x 255 yuni yuni 24576 Jul 15 16:26 ../ -rw------- 2 yuni yuni 48 Jul 15 16:16 file_2 lrwxrwxrwx 1 yuni yuni 39 Jul 15 16:40 homework_backup -> /home/yuni/archive/homework_backup/
Note the link count of file_2, the file type and the symbolic link symbol of homework_backup.