Links are awesome !

While reading a book on linux ( The linux command line ), I came through the concept of links. There are two types of links in linux, hard link and symbolic link. The latter was created to overcome the limitations of the former.

Hard links

The hardlinks was the method adopted by the earlier linux versions. It was the original way of creating a link in linux. Every file will have a filename, by default this filename is attached to the file using a hardlink, therefore every file has a hardlink by default. Now coming to the limitations of hardlink.

  • Hardlinks cannot reference a file outside it’s own filesystem.

  • They cannot reference a directory.

A hardlink can be created by using the following command.

$ ln file linkname

A hardlink can be removed by using the following command.

$ unlink linkname

Now the awesome part of the links is that whenever you make any changes to content of the link, it is automatically applied to the file.

Symbolic links

The symbolic links allows you to create links to the directories as well. Also it allow you to create a link that can reference a file outside it’s own filesystem.

A symlink can be created by using the following command.

$ ln -s <directory/file> linkname

A symlink can be removed by using the following command.

$ unlink linkname

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s