Soft link (symbolic link / symlink):
It is similar to “shortcuts” in windows operating system. Removing the original file does not remove the attached symbolic link or symlink, but without the original file, the symlink is useless
To create a soft link already existing file:-
#ln –s <target file> <new file (name of symlink)>
It simply contains the pointer to the location of the destination file. In more technical words, in soft link, a new file is created with a new inode, which have the pointer to the inode location of the original file. It's a special file type whose data part carries a path to another file.
- If you want to link directories, then you must be using Soft links, as you can’t create a hard link to a directory.
- If you want to link files across the filesystems, e.g EXT4, NFS. you can only use symlinks/soft links.
It is simply giving one more name or label to existing file.
In technical words, only an entry into directory structure is created for the file with its inode number, but it points to the inode location of the original file. This means there is no new inode creation in the hard link. Inode of file maintains count of links pointing to this file, when count becomes zero, inode is free to deallocate.
To create hard link to existing file:-
#ln <target file> <hardlink name>
If you try #ls -il , you will see that both files have same inode number , files have the same file permissions and the same size. Because that size is reported for the same inode, we can see that a hard link does not occupy any extra space on your space
- '..' is a hardlink to the file that implements the immediate parent of the current directory.
- If you move the source file to some other location on the same filesystem, the hard link will still work, but soft link will fail.
- Hard links takes very small amount of space, as there are no new inodes created while creating hard links.
- If you want to make sure safety of your data, you should be using hard link, as in hard link, the data is safe, until all the links to the files are deleted, instead of that in soft link, you will lose the data if the master instance of the file is deleted.
- Hard link can only refer to data that exists on the same file system.
- Hard link does not work on directory.