How to remove symbolic links on Linux


In this tutorial we will show you how to remove symbolic links on Linux. For those of you who did not know, a symbolic link (also known as a symlink) is a term or special type of file in Linux that points to another file or directory. Symbolic links are generally used to link libraries. Also used to link log files and folders to mounted Network File System (NFS) parts.

This article assumes that you have at least basic knowledge of Linux, know how to use the shell and most importantly, that you host your website on your own VPS. The installation is quite simple and requires you to run in the root account, otherwise you may need to add ‘sudoto the commands for root privileges. I will show you step by step to remove symbolic links on Linux.

Symbolic links can be removed with two commands: rm and unlink. You can use any of the following commands to delete symbolic links.

  • Remove symbolic links with rm

To delete a symlink, run rm command with the symbolic link name as argument:

rm symlink

To be prompted before removing symlink, use -i option:

rm -i symlink

If you want to delete more than one symbolic link, you can send multiple symlink names as arguments space separated:

rm symlink-name-1, symlink-name-2

Option rm commands:

-i hat mean interactive ask for delete file
-f force not ask just do action delete force
-r recursive . use for Directory
  • Remove symbolic links with unlink

The best way to delete a symlink is with the appropriate name “unlink“Tool. Using unlink to delete a symlink is extremely simple, you just need to tap the symbolic link to delete the link:

unlink symlink
  • Find and remove broken symbolic links.

The search command has an option that allows you to find sym links that point to files that no longer exist. This command lists symlinks in the current directory:

find . -type l

Once you have received the broken symbolic links, use -delete the option with find command shown below:

find /path/to/directory -xtype l -delete

Congratulations! You have removed symbolic links. Thank you for using this wizard to remove symbolic links on the Linux server.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More