← back to the blog


Linux Symlink Folder (soft link, symbolic link) Eloquent explanation

Posted on June 19th, 2019 by George

Create a  symbolic link (symlink):

ln - create link between files (hard link)
ln -s - create symbolic link instead of hard link

 

Proof of concept:

ln -s SOURCE DESTINATION

Here is an example where the directory named as test-directory (the source in this example) it is used to create a soft link to the destination directory named symlink.

Example: 

SOURCE = /home/username/Desktop/test-directory
DESTINATION = /home/username/Desktop/symlink

/*username in this example is georgerdp-gtx */

//You can inspect the directories with ls -a ( ls -a " ls - list directory contents" , "-a - all")
//You can inspect the directories with ls -s (" -s - see the size of each file in the directory)

//1. In the terminal we can see that symlink and test-directory located on home Desktop are both empty.
// we use  ~ instead of /home/username (~ = tilde is the shortcut for user home directory but has other use cases also)

//Terminal command:

***@***:~/$ ls -s ~/Desktop/test-directory ~/Desktop/symlink

// Terminal output: 

/home/georgerdp-gtx/Desktop/symlink:
total 0

/home/georgerdp-gtx/Desktop/test-directory:
total 0

//2. In the next step we use ln -s with the SOURCE directory and DESTINATION directory
// to create the soft link 

//Terminal command:

***@***:~/$ ln -s ~/Desktop/test-directory ~/Desktop/symlink

//3. On the last step we use ls -s again to inspect the directory and content

//Terminal command:

***@***:~/$ ls -a ~/Desktop/test-directory ~/Desktop/symlink

// Terminal output: 

/home/georgerdp-gtx/Desktop/symlink:
.  ..  test-directory //symlink directory located on home Desktop has now the soft link
/home/georgerdp-gtx/Desktop/test-directory:
.  ..


 

Now if you check the properties of test-directory located on deskop you wll see that the type is Type: Folder (inode/directory) while

the test-directory located in symlink is of type  Link to Folder (inode/directory)