How to Create Symbolic Links in Linux/Unix?

A symbolic link creates a file in your directory and is a shortcut to a file or folder. It’s similar to the Windows shortcut file.

ln is a command-line utility for creating links between files. By default, the ln command creates hard links. To create a symbolic link, use the -s (–symbolic) option.

Create Symbolic for Folder

I have a directory- let’s say apache-tomcat-9.0.27 under /home/narayanatutorial/installation/  However, I want a shortcut/symbolic for apache-tomcat-9.0.27 in /home/narayanatutorial/

Syntax:

ln -s <source-folder-path> <short-cut-folder-path>

Example:

ln -s  /home/narayanatutorial/installation/apache-tomcat-9.0.27  /home/narayanatutorial/tomcat

Here -s stands for symbolic.

Create Symbolic for File

I have a file – let’s say apache-tomcat-9.0.27/conf/server.xml under /home/narayanatutorial/installation/  However, I want a create shortcut/symbolic link for server.xml  in /home/narayanatutorial/

Syntax: 

ln -s <source-file-path> <short-cut-file-path>

Example:
 
ln -s  /home/narayanatutorial/installation/apache-tomcat-9.0.27/conf/server.xml  /home/narayanatutorial/tomcat-server.xml

 

Remove Symbolic via rm

Remove symbolic command is a simple like as remove the file

Syntax:

rm <symbolic-file-path>

Example:

rm /home/narayanatutorial/tomcat

Remove Symbolic via unlink

We can use the unlink command to remove the symbolic as follows

Syntax:

unlink <symbolic-file-path>

Example:

unlink /home/narayanatutorial/tomcat

Overwriting Symbolic or Forcefully change the sysmbolic

If you try to create a symbolic link that already exists , the ln command will print an error message.

To overwrite the destination path of the symlink, use the -f (–force) option.

Syntax: 

ln -sf <source-file-path> <short-cut-file-path>

Example:
 
ln -sf  /home/narayanatutorial/installation/apache-tomcat-9.0.27/conf/server.xml  /home/narayanatutorial/tomcat-server.xml

 

 

Leave a Reply