A symbolic link, also known as symlink, is a file that points to another file. The file points to can be in the same or different directory. It is similar to the shortcuts in Windows OS.

In today’s post, we will be describing how to remove a symbolic link in Linux. Note that removing a symbolic link does not affect the file it points to.

Before removing a file, you can verify whether it is a symbolic link using the ls -l command. It will also show you the file or directory that it points to.

The l in permissions (lrwxrwxrwx) confirms that it’s a symbolic link.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/1-2.png" data-lazy- height="253" src="data:image/svg xml,” width=”803″>

Remove a Symbolic Link using the unlink command

The unlink command is used for removing a single file from the file system. To remove a symbolic link in Linux, type the unlink command followed by the name of the symbolic link and hit Enter:

$ sudo unlink symbolic_link

Replace symbolic_link with the name of the symbolic link you want to remove. After that, you can use the ls -l command to confirm if the symlink has been removed.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/2-2.png" data-lazy- height="288" src="data:image/svg xml,” width=”655″>

Remove a symlink that points to a directory, don’t use the slash after the directory name. Let’ say we want to remove a symbolic link directory named Docs, as shown in the following screenshot:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/3-2.png" data-lazy- height="157" src="data:image/svg xml,” width=”883″>

The command to remove the symlink directory will be:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/4-2.png" data-lazy- height="285" src="data:image/svg xml,” width=”573″>

Remove a Symbolic Link using the rm command

The rm command can also be used to remove a symbolic link. For removing a symbolic link in Linux, type the rm command followed by the name of the symbolic link and hit Enter:

After that, you can use the ls -l command to confirm if the symlink has been removed.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/5-2.png" data-lazy- height="291" src="data:image/svg xml,” width=”598″>

You can also use the -i flag with the rm command to prompt for confirmation.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/6-1.png" data-lazy- height="93" src="data:image/svg xml,” width=”379″>

Removing a symlink that points to a directory, don’t use the slash after the directory name. Let’ say we want to remove a symbolic link directory named Docs, as shown in the following screenshot:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/7-1.png" data-lazy- height="157" src="data:image/svg xml,” width=”883″>

The command to remove the symlink directory will be:

After that, you can use the ls -l command to confirm if the symlink has been removed.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/8-1.png" data-lazy- height="266" src="data:image/svg xml,” width=”572″>

That is all there is to it! You have learned to remove a symbolic link in Linux OS using the unlink and rm command in this post. While removing a symbolic link, make sure only to remove the symbolic link itself, not the file or directory it is linking to.

About the author

<img alt="" data-del="avatar" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/karim.png" height="112" src="data:image/svg xml,” width=”112″>

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.