Monday, April 23, 2012

Symbolic Links in Unix & Linux

Symbolic links have played vital roles in many of linux development that I have been involved in. Hence, I thought it would do justice to write something on them.

Symbolic links are of 2 types - soft vs hard links.

 

·         Soft links are pointers to programs, files, or directories located elsewhere (just like Windows shortcuts)

·         Soft links don’t die if the source is deleted

 

·         Hard links are pointers to programs and files, but NOT directories

·         Hard links don’t die if the source is deleted

 

Let’s look at some commands to play with symbolic links.

 

Creating a symbolic link:

[yassar@machine data01]$ ln -s pointingToFolder linkName

This will create the linkName pointing to the folder



Displaying symbolic link(s):
[yassar@machine data01]$ ls -la
lrwxrwxrwx.  1 yassar yassar   35 Apr  2 21:35 workspace -> /data/workspaces/branches/Trunk_V3.0.1

 

This would display the folder details together with the actual link path



Updating a symbolic link:

[yassar@machine data01]$ ln -s pointingToDifferentFolder existingLinkName

 

This will use an existing link to point to a new folder



Deleting a symbolic link:
[yassar@machine data01]$ rm latest previous

 

This simply deletes the link.

 

Once you’re in the link directory, you may check the actual path:

[yassar@machine data01]$ pwd -P