Tuesday, November 17, 2020

How to create a shortcut (Symbolic Links) to files and folders in Linux


Shortcut in linux

Creating Shortcut or Symbolic Links to files and folder is a very easy task to do. There are few files and folders which we need to access frequently, to access these file or folders we need to dig through the file system. This task became more irritating when using Linux without GUI.

We can create Symbolic links to access the files and folders more quickly.

Command


ln -s absolute_path_to_file_access_quick absolute_path_to_destination


Example


ln -s /home/guide-father/Documents/Guide ~/Desktop/

This will create a shortcut to the Guide folder on the Desktop. This command works both with and without GUI Linux platforms. 

GUI shortcut icon

Bonus Info

Other than Symbolic Links you can also create Hard Links by following command

ln absolute_path_to_file_access_quick absolute_path_to_destination


The main difference between hard links and soft links (Symbolic Link ) is if the real file/folder is deleted then Symbolic Link will not work while the hard link will continue to work.

Explanation

An inode is a data structure that stores various information about a file(like permissions, file size, owner, group, etc..) in Linux. Each inode is identified by an integer number.
You can check the number by 

ls -il

you should get something like following

29657809 -rw-rw-r-- 1 guide guide 0 Nov 17 21:46 random
29648880 -rw-rw-r-- 1 guide guide 0 Nov 17 21:46 test

here the number is the in inode integer associated with the files

Hard link refers to the inode directly while the symbolic link refers to the file itself, hence when the original file lost the symbolic link stop working.
symbolic hard link