Friday, December 2, 2011

hardlink vs symbolic link

Hardlink or hardlinks cannot be created for directories (folders). Hard link can only be created for a file.


Symbolic links or symlinks can link to a directory (folder).

Removing the original file that your hard link points to does not remove the hardlink itself; the hardlink still provides the content of the underlying file

Removing the original file does not remove the attached symbolic link or symlink, but without the original file, the symlink is useless


If you remove the hard link or the symlink itself, the original file will stay intact




  • How to create a hard link or hardlink?


use the ln command to create a hard link.where fileA is the original file and fileB is the name you want to give to the hardlink

ln fileA fileB

both files fileA and fileB have the same inode number
both files have the same file permissions and
the same size


ln Command Syntax

The syntax is as follows for Unix / Linux hard link command:
ln {source} {link}

Where,

    source is an existing file.
    link is the file to create (a hard link).


# ln a.txt harda.txt

1898766 -r-xr-xr-x 2 root     root        7 Dec  1  2011 a.txt
1898766 -r-xr-xr-x 2 root     root        7 Dec  1  2011 harda.txt
1898831 lrwxrwxrwx 1 root     root        5 Nov  6 15:38 symboa.txt -> a.txt



  • How to create a symlink?


where fileA is the original file and fileB is the name you want to give to the symbolic link

ln -s fileA fileB

The inode is different for the original file and for the symbolic link

the symbolic link has different permissions than the original file (because it is just a symbolic link).

The content of the symlink is just a string pointing to the original file

The size of the symlink is not the same as the size of the original file.

The symbolic link is a separate entity and as such occupies some space on your hard drive



ln -s a.txt symboa.txt

ls -li
1898766 -r-xr-xr-x 1 root     root        7 Dec  1  2011 a.txt
1898831 lrwxrwxrwx 1 root     root        5 Nov  6 15:38 symboa.txt -> a.txt

The inode is different for the original file and for the symbolic link
the symbolic link has different permissions than the original file (because it is just a symbolic link).
The size of the symlink is not the same as the size of the original file



  • Can I make a symlink to a hard link?


Yes. The hard link functions the same way like the original file; therefore, you can make symlinks to it.


http://www.maxi-pedia.com/difference+between+symbolic+link+and+hard+link