Both hard and soft (also called symbolic) links are useful for providing alternative names for files and directories. Instead of having to type a long and difficult path to a file like: /usr/share/doc/package/data/2013/october/10/valu able-information.txt
…a link name for the same file may be simply: ~/valuable.txt
To understand how links work, it is helpful to understand how the filesystem keeps track of files. For every file that is created, there is one block of data called an inode table that stores the meta-information of the file, such as permissions, ownerships, timestamps and pointers to where the file’s contents are stored. The inode table includes almost all information about a file except the file name.
Understanding the Filesystem(cont) Each inode table is associated with a unique inode number. The ls -i command will display the inode number for each file. The directory stores the names of all the files within the directory and their associated inode number. When access is attempted on a file, the system reads the directory data to find the file name and then retrieves its data by looking up the data blocks referenced in its inode.
Every file has at least one hard link to it (for the original file name). The link count number appears between the permissions and the user owner in a detailed listing: $ echo data > file.original $ ls -li file.*
To create hard links, the ln command is used with the first argument being an existing file name and the second argument being the new file name to link to it: $ ln file.original file.hard.1 $ ls -li file.*
A soft (symbolic) link is a file that points to another file name. Soft links have a file type of "l“. Soft links are similar to shortcuts in Windows. Several soft links already exist on the system including /etc/grub.conf: $ ls -l /etc/grub.conf lrwxrwxrwx. 1 root root 22 Feb 15 2011 /etc/grub.conf -> ../boot/grub/grub.conf