Symlinks and hard links

A symbolic link (or symlink or soft link) is a special type of file which contains a reference to another file or directory. If a symlink is deleted, the target file or directory is still there. A symlink can still exists even if its target is deleted. Then, the soft link is orphaned/broken.

To create a symlink :

fool@localhost:~$ ln -s path_to_the_target_file link_name

A hard link refers to the specific location of physical data.

To create a hard link :

fool@localhost:~$ ln target link_name

The hard link points to the same data than the file considered as the target. If you remove a hard link, you remove the data as well.

In the Debian coreutils package, there are other commands for managing soft links and hard links.

Instead of using ln without options, link can do the job :

fool@localhost:~$ link file_name link_name

To see which target file a symlink points to, you can use readlink :

root@localhost:~# cd /etc/rc2.d && readlink S30gdm

The coreutils package is installed by default at the time you have installed Debian.


Leave a Reply

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

You are commenting using your 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.