YouTube Icon

Code Playground.

How to Remove (Delete) Symbolic Links in Linux


How to Remove (Delete) Symbolic Links in Linux

An emblematic connection, otherwise called a symlink, is a unique kind of record that focuses to another document or registry. It is something like an easy route in Windows. A symlink can highlight a document or an index on the equivalent or an alternate filesystem or segment. 

In this guide, we will tell you the best way to eliminate (erase) emblematic connections in Linux/UNIX frameworks utilizing the rm, unlink, and discover orders. 

Before You Begin

To eliminate a symlink, you have to have composing consents on the catalog that contains the symlink. Else, you will get "Activity not allowed" blunder. 

At the point when you eliminate a symlink, the record it focuses to isn't influenced. 

Utilize the ls - l order to check whether a given record is a representative connection, and to discover the document or catalog that emblematic connection highlight. 

ls -l /usr/bin/python
lrwxrwxrwx 1 root root 9 Apr 16  2018 /usr/bin/python -> python2.7

The main character "l", shows that the document is a symlink. The "- >" image shows the record the symlink focuses to. 

Remove Symbolic Links with rm

The rm order eliminates given records and indexes. 

To erase a symlink, summon the rm order followed by the representative connection name as a contention: 

rm symlink_name

On progress, the order exits with zero and shows no yield. 

With rm you can erase more than one representative connections on the double. To do that pass the names of the symlinks as contentions, isolated by space: 

rm symlink1 symlink2

To get incited prior to eliminating the symlink, utilize the - I choice: 

rm -i symlink_name

To affirm type y and press Enter. 

rm: remove symbolic link 'symlink_name'? 

In the event that the representative connection focuses to a catalog, don't attach the/following slice toward the end. Else, you will get a mistake: 

rm symlink_to_dir/
rm: cannot remove 'symlink_to_dir/': Is a directory

In the event that the name of the contention closes with/, the rm order expects that the document is an index. The blunder happens in light of the fact that, when utilized without the - d or - r choice, rm can't erase registries. 

To play it safe, never - r choice while eliminating emblematic connections with rm. For instance, on the off chance that you type: 

rm -f symlink_to_dir/

The substance of the objective registry will be erased. 

Remove Symbolic Links with unlink

The unlink order erases a given record. Dissimilar to rm, unlink acknowledges just a solitary contention. 

To erase a representative connection, run the unlink order followed by the symlink name as a contention: 

unlink symlink_name

In the event that the order executes effectively, it shows no yield. 

Try not to annex the/following cut toward the finish of the symlink name on the grounds that unlink can't eliminate registries. 

Find and Delete Broken Symbolic Links

In the event that you erase or move the source document to an alternate area, the representative record will be left hanging (broken). 

To locate all wrecked emblematic connections under a given registry, run the accompanying order: 

find /path/to/directory -xtype l

The order will list all wrecked connections under the index and its subdirectories. 

On the off chance that you need to prohibit the symlinks that are contained in the subdirectories pass the - maxdepth 1 alternative to discover : 

find /path/to/directory -maxdepth 1 -xtype l

When you locate the wrecked symlinks, you can either physically eliminate them with rm or unlink or utilize the - erase alternative of the discover order: 

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


To eliminate a representative connection, utilize either the rm or unlink order followed by the name of the symlink as a contention. While eliminating an emblematic connection that focuses to a registry don't attach a following slice to the symlink name. 

On the off chance that you have any inquiries or criticism, don't hesitate to leave a remark.