links or shortcuts in linux
Today we will cover links or in the Windows world, shortcuts.
Linking lets you refer to a file or directory, and you can refer to file or directory using a different names.
The command for creating a link in linux is the “ln” command. Linux has different types of links called symbolic links (soft links) and hard links.
To understand the difference we must first have some knowledge about linux files. Each file in linux is assigned an inode number and a file name. The inode number is a unique number that identifies the file and is assigned by the operating system, and describes the location of the files data on the volume. The file name is the text representation of the inode number.
Hard Links
Multiple file names can represent the same inode number. A hard link allows multiple file names to point to the same inode number and thus the same file data on the volume.
The feature of hard links is that if you delete one file name, the other filename will remain and so will the inode and file data. To delete the file data from the volume you must delete all hard links associated with the file data.
Hard link does have its limitations. Hard links cannot be used for linking directories or for linking across different file systems.
Syntax for creating links is
ln file_name link_name
Create a hard link called “hardlink” to the file “file1″:
tmp]$ ln file1 hardlink
Soft Links
Soft link or symbolic links are more common. With a soft link the file name is associated with the target file name and not the target files’ inode.
One of the big differences with soft links is that if you delete the target file, the link or links will no longer work, because they are only pointing to the target file name and it is now gone. This also applies if you change the file name of the target file.
Soft links can be used for linking directories or for linking across different file systems.
-s – make symbolic links instead of hard links
Create a soft link called “softlink” to the file “file2″:
tmp]$ ln -s file2 softlink


