How To Create Symbolic Links In Linux Using Ln Command

ln command is used in Linux to create the symbolic links. Symbolic links are great way to save your disk space. If the data is needed in multiple places/directories, rather than duplicating the data, one can create link to data and access it from his/her current directory.

Lets first see, how we can create symbolic link to a file.


Where FILE is to which we want to create a LINK

ex: lets create a file call test.txt in tmp directory and create a link to this file in the home directory...

➜ /home pwd
➜ /home touch /tmp/test.txt
➜ /home ln -s /tmp/test.txt .
➜ /home ls -lrt test.txt
lrwxrwxrwx 1 root root 13 Oct 24 05:00 test.txt -> /tmp/test.txt

If the file test.txt link already exists in your home directory then you use -f (force) switch to do that


➜ /home ln -s /tmp/test.txt .
ln: failed to create symbolic link ‘./test.txt’: File exists
ln -sf /tmp/test.txt .

To remove the link, Use rm command...

rm test.txt