Sometimes it is convenient to have access to a file by multiple names. This can be accomplished by creating a link. There are two types of links: hard and symbolic.
ln xyz.java xyz.java.save
The file xyz.java.save is a hard link to the file xyz.java. That means if we change the content of either file, the contents of the other file will change as well. If we accidentally delete xyz.java, then we still have the file xyz.java.save. What is interesting is that these two files are two names for the same data on the disk. Deleting a file merely removes one of the links. The data on the disk is removed only if no links remain to that file. So making a hard link is different than making a copy. It does not make a copy of the data. See the example below.
[alice@onyx ~]: ln xyz.java xyz.java.save [alice@onyx ~]: ls -l xyz.java* -rw-rw-r-- 2 alice alice 2374 Dec 3 10:50 xyz.java -rw-rw-r-- 2 alice alice 2374 Dec 3 10:50 xyz.java.save [alice@onyx ~]: rm xyz.java rm: remove regular file `xyz.java'? y [alice@onyx ~]: ls -l xyz.java.save -rw-rw-r-- 1 alice alice 2374 Dec 3 10:50 xyz.java.save [alice@onyx ~]:
[alice@onyx ~]: ln -s xyz.java f1 [alice@onyx ~]: ls -l f1 xyz.java lrwxrwxrwx 1 alice alice 8 Dec 3 10:57 f1 -> xyz.java -rw-rw-r-- 1 alice alice 2374 Dec 3 10:57 xyz.java [alice@onyx ~]: rm xyz.java rm: remove regular file `xyz.java'? y [alice@onyx ~]: ls -l f1 xyz.java ls: xyz.java: No such file or directory lrwxrwxrwx 1 alice alice 8 Dec 3 10:57 f1 -> xyz.java [alice@onyx ~]: cat f1 cat: f1: No such file or directory [alice@onyx ~]:
Symbolic links are useful for pointing to other directories or files without having to copy them, which would end up in duplicates that waste space and have to be kept consistent.