← 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:


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.


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: 

total 0

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: 

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


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)