If you are using a really long path to reach a directory (my/really/long/path/to/the/directory) frequently, it will get painful to type the long path every time to get there.
Well, the command “ln -s” offers you a solution by letting you create a soft link. The ln command in Linux creates links between files/directory. The argument “s” makes the the link symbolic or soft link instead of hard link.
Creating soft link with ln -s
You can easily create a soft link with a simple short name for the long-path directory and use the simple name to get to your long-path directory.
For example, use “ln -s” by typing the following command at your terminal.
ln -s /my/long/path/to/the/directory easyPath
This will create a soft link (or symbolic link) for the directory. Once you create a soft link , you will see the new simple path directory in the current directory. And the simple path will be linked to the long path, you can see that by using “ls -l”, like
easyPath -> /my/long/path/to/the/directory
If you have color coded the files and directories, the softlink paths will be in a different color than regular directories. And use the simple path directory every time to reach to the long-path directory. It can save you loads of key strokes and valuable time.
Another common use of creating a softlink with “ln -s” is often you may have your primary data in a directory that can change, but have softlinked directory, that is fixed, pointing to the primary data directory. So for all your work, you will be accessing data from soft link that is the same while the underlying primary data directory may change often. (Yes, one needs to resent the soft link every time the primary data directory changes)
Setting up alias
Another possible solution is to use “alias” and put that alias in your .bashrc/.profile or other the shell file that you use. The way to do that is use it like as given below.
alias easyPath = “cd /my/long/path/to/the/directory simplePath”
As you can see the above “alias” option only creates an alias for “cd ” to the directory. You need to create other aliases to perform more operations. On the other hand the soft link lets you treat like any other directory and perform any operations you like.
How to Remove soft link or Symbolic link?
In case you decide to remove the soft or symbolic link, it is pretty easy to do. There are two linux commands you can use to remove soft link
One is simply use “rm” command
rm easyPath
The second way is to use the unlink command followed by the softlink name.
unlink easyPath
Note that it removes only the soft link that you created, it does not remove the original directory/file that you soft linked.