Friday, December 18, 2015

symbolic link or symlink in unix linux


Whenever I do scripting or write any UNIX script I always write for symlinks rather than pointing to absolute path of directories in UNIX. It gives you flexibility of changing the symlink or soft link without making any change on your tried and tested scripts. I have worked on many different core Java projects which run on Linux and UNIX machine and make extensive use of UNIX symbolic links or symlinks.
Below are some of example of UNIX symlinks I have seen during my projects of involving UNIX soft links:

1) In our project our Java process picks latest version of package for executing, which is a UNIX soft link. So whenever we do a release, by using tar archives,  we just need to update latest UNIX symlink which makes release seamless and rollback very easy which in tern increases stability and predictability of our Java application.

2) All our UNIX script takes the location as argument so they are agnostic about the absolute path of resources and these resources are provided them via UNIX soft links and environment variables. This feature of our scripts saves a lot of time whenever we need to do any migration which involves changing location of resources.

3) An important point about UNIX soft link is that they inherit the permission of the directory , to which they are pointing out. which means if you change permission of directory by using  chmod command in Unix, permission on soft link will also be updated.

Creating a symbolic/Soft link


Here we will see how to create soft link and hard link in UNIX, also known as symbolic link or symlink in Linux.

$ ln -nsf 1.2 latest

This will create a soft link name “latest” which will point to directory “1.3”. Let’s see whether this soft link in UNIX created or not.  We can see that in last line a symlink is created. Notice lrwxrwxrwx  (first “l” denotes it is a link in UNIX)

Updating a symbolic/Soft link


We have seen how to create a symlink in UNIX now we will see how we can update that symlink or soft link  without removing it.

$ ln -nsf 1.3 latest

This will update the symlink latest to point to directory “1.2” instead of “1.3”. notice command line option “-nsf”. 

Removing a Symbolic/Soft Link


$ rm latest previous



if you liked this article help me buying the below nice MI Band 2


No comments:

Post a Comment

Java garbage collection

In this post , we ’ ll take a look at how garbage collection works , why it ’ s important in Java , and how it works in...