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.
[amit@onyx handouts]: ln xyz.java xyz.java.save [amit@onyx handouts]: ls -l xyz.java* -rw-rw-r-- 2 amit amit 2374 Dec 3 10:50 xyz.java -rw-rw-r-- 2 amit amit 2374 Dec 3 10:50 xyz.java.save [amit@onyx handouts]: rm xyz.java rm: remove regular file `xyz.java'? y [amit@onyx handouts]: ls -l xyz.java.save -rw-rw-r-- 1 amit amit 2374 Dec 3 10:50 xyz.java.save [amit@onyx handouts]:
[amit@onyx handouts]: ln -s xyz.java f1 [amit@onyx handouts]: ls -l f1 xyz.java lrwxrwxrwx 1 amit amit 8 Dec 3 10:57 f1 -> xyz.java -rw-rw-r-- 1 amit amit 2374 Dec 3 10:57 xyz.java [amit@onyx handouts]: rm xyz.java rm: remove regular file `xyz.java'? y [amit@onyx handouts]: ls -l f1 xyz.java ls: xyz.java: No such file or directory lrwxrwxrwx 1 amit amit 8 Dec 3 10:57 f1 -> xyz.java [amit@onyx handouts]: cat f1 cat: f1: No such file or directory [amit@onyx handouts]:
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.