What is Hard Link and Soft Link ? why we require them ?

Hard Link and Soft Link are the two words which will be heard when you are using Linux (any of it’s distro’s).

what is a hard link?

before that you need to know what is inode.(pronounced as  “I node”)  a concept of unix-like OS’s

In simple terms inode is a data structure which stores file attributes and disk block locations (simply details about a file object like metadata and permissions etc..,)

Now imagine a situation where you have a file (any type of file). you want to create a replica of that file such that whatever changes that are made in replica must be effected in original file or even vice-versa (also replica and original file may be in different directories but on one system ) i.e it is possible to create a number of different names that all refer to the same contents

when you are in above situation then you need to think of  “Hard Links”.A hard link is a replica of another file which points to the original file using “inode numbers” . Commands executed upon any of these different names will then operate upon the same file contents.

Multiple directory entries may map to the same inode On non-Unix systems that do not allow such multiple mappings, you’d just call such mappings “files”.

To create a Hard Link —>open terminal then type command

 ln old-filename  new-filename

where ln – make links between files   ( type ” man ln ” in terminal)

Note:– If you want to delete a file or hardlink then you can apply “rm” command but to completely wipe out the hardlinks and original file you need to delete all hardlinks and original file also i.e deleting one hardlink or original file wont delete completely your file contents

also you cannot create hardlinks for directories.

Disadvantage of Hard Link is  when your using NFS and want hard links on different systems then no it’s not possible –here comes symbolic-links or symlinks

what is symbolic link?

A symbolic link, also termed a soft link, is a special kind of file that points to another file, much like a shortcut in Windows or a Macintosh alias.

that is symbolic link is just a shortcut when you create a symbolic link for a file then the symbolic by itself doesnot consists of any of file contents except  “Name “(i.e just try to relate to windows shortcuts ..,when you create a desktop shortcut in windows that doesn’t mean that particular directory or file or software is going to be copied to dekstop but just a shortcut icon is created–soft link or symlink is the same)

the advantage of sym-links over hard links is that when you want to create sym-links of files on other system using NFS then this is very useful unlinke hardlinks

Also, when you delete  the original file, symbolic links to that file become unusable, whereas hard links preserve the contents of the file.

to create a symlinks:-

ln -s  sourcefilename  yourfilename

Note: If you delete the source file or move it to a different location, your symbolic file will not function properly. You should either delete or move it. If you try to use it for other purposes (e.g., if you try to edit or execute it), the system will send a “file nonexistent” message.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s