Wednesday, September 30, 2015

Create A Symbolic Link In Linux

    Since you came across this blog, this mean that you might want to know how to create a symbolic link in Linux using a command line.

    Let's take the following problem settings, suppose that you have a directory that is being used by many programs. For example, "~/.cache". Suddenly, the storage disk is full, then you need to make a decision of freeing space or either move the directory into another storage disk. Yet, the simplest solution is to use is to create a symbolic link. In favor to avoid making any changes to all program that use the "~/.cache" Folder.

1) Create a directory at the secondary storage.

% mkdir /storage/

2) copy the folder to the secondary storage.  

% cp -r ~/.cache /storage/

3) Remove the shared directory that you want to create a symbolic link for. 

% rm -rf ~/.cache

4) Create the symbolic link. 

% ln -s /storage/.cache  ~/


    By now you should find a symbolic link under your directory look like this " ~/.cache@". This means that you can navigate to the shared directory as usual without any effect. For instance, if you write cd ~/.cache then it will take you to /storage/.cache/


Another Example of why the one need to use a symbolic link. Suppose that you have a very long directory as this " /home/world/northAmerica/us/minnesota/saintpual/louai", then it is annoying to type this every time you use your computer. In this case a symbolic link sounds a wonderful idea.

Simply create a symbolic link in your home directory

% cd ~ && ln -s /home/world/northAmerica/us/minnesota/saintpual/louai ~/

Now when you can type only this to navigate to the folder.

% cd ~/louai

No comments:

Post a Comment