AlmaLinuxCentOSDebianLinuxLinux MintManjaroTutorialsUbuntu

How To Remove Symbolic Links on Linux

Remove Symbolic Links on Linux

In this tutorial, we will show you how to remove symbolic links on Linux. For those of you who didn’t 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. In general Symbolic links are used to link libraries. Also, used to link log files and folders on mounted NFS (Network File System) shares.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step to remove symbolic links on Linux.

Prerequisites

  • A server running one of the following operating systems: Ubuntu or CentOS.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Remove Symbolic Links on Linux

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

  • Remove Symbolic Links with rm

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

rm symlink

To get prompted before removing the symlink, use the -i option:

rm -i symlink

If you would like to delete more than one symbolic link, you can pass multiple symlink names as arguments with 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 remove a symlink is with the appropriately named “unlink” tool. Using unlink to delete a symlink is extremely simple, you just need to point it at the symbolic link to unlink and remove:

unlink symlink
  • Find and Delete Broken Symbolic Links.

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

find . -type l

Once get the broken symbolic links, use the -delete option with the find command as shown below:

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

Congratulations! You have successfully removed symbolic links. Thanks for using this tutorial to delete symbolic links on the Linux server.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!
Back to top button