How To: Linux Delete Symbolic Link ( Softlink )

How do I delete symbolic link (softlink) in Linux operating system using a command prompt? How can I remove symbolic links in Linux?

A symbolic link (also known as a “soft link” or “symlink”) consists of a special type of file that serves as a reference to another file or directory. You can use any one of the following command to delete or remove symbolic links in Linux operating systems:
  • rm command – Removes each given FILE including symbolic links in Linux.
  • unlink command – Deletes a single specified file name including symbolic links in Linux.
Tutorial details
Difficulty level Easy
Root privileges No
Requirements Linux terminal
Est. reading time 4 minutes
Let us see some examples about to remove (delete) symbolic links in Linux.

Warning: Care must be taken with the following rm, unlink, and find command as those commands won’t prompt for removal confirmation. The author or nixCraft site is not responsible for any data loss. Please use all command with care and think twice before you press the [Enter] key. Always keep a verified backup of all files and data.

Linux Delete Symbolic Link File

Use the following syntax:

rm linkname
unlink linkname


First, we are going to create a new symbolic link in Linux using the ln command. Use the cd command to /tmp/ directory:

cd /tmp/
## create a new symbolic for demo purpose ##
ln -s /etc/resolv.conf dns
## List it ##
ls -l dns

Sample outputs:

lrwxrwxrwx 1 vivek vivek 16 2009-08-16 04:28 dns -> /etc/resolv.conf

Now we are going to delete the dns symbolic link using the rm command or unlink command as follows:

rm dns
## OR ##
unlink dns

Verify it using the ls command:

ls -l dns
ls -l /etc/resolv.conf

Getting confirmation prompt

We can force prompt before every removal of symbolic links by passing the -i to the rm:
rm -i {link-name}
rm -i -v test-link

rm: remove symbolic link 'test-link'? y
removed 'test-link'

Delete Symbolic Link Directory

The syntax is same:

rm linkDirName
unlink linkDirName

Please avoid appending / at the end of linkDirName. cd in to the /tmp/ using the cd command:

cd /tmp/
## create a new symlink for demo purpose ##
ln -s /etc test
## List it ##
ls -ld test

Sample Output:

lrwxrwxrwx 1 vivek vivek 4 2009-08-16 04:31 test -> /etc

Now delete the test symbolic link directory using any one of the following command:

rm test
## OR ##
unlink test

Make sure symbolic link is removed using the ls command:

ls -ld test
ls -ld /etc

Remove Symbolic Links with find command

Here is we can search and list all symbolic links using the find:

find {/path/to/dir} -type l -action
find {/path/to/dir} -type l -name 'files-regex-to-search' -action
find {/path/to/dir} -type l -iname 'Case-Insensitive-files-regex-to-search' -action
find {/path/to/dir} -lname 'files-regex-to-search'  -action

Say list all symlinks in /tmp/bin/, run:
find /tmp/bin/ -type l -print
Only list *.txt or *.sh symlinks, run:

find /tmp/bin/ -type l -iname "*.sh" -print
find /tmp/bin/ -type l -iname "*.txt" -print
## modern syntax for GNU/find ##
find /tmp/bin/ -lname "*.txt" -print
find /tmp/bin/ -lname "*.db" -print
find /tmp/bin/ -lname "*.sh" -print

Find all symbolic links with find and delete them

All you have to do is replace the -print action with the -delete as follows to delete all ‘*.sh’ symlinks:
find /tmp/bin/ -lname "*.sh" -delete
To get confirmation use the following syntax when you need to find all “*.txt” symlinks and delete them:

find /tmp/bin/ -type l -name "*.txt" -exec rm -i {} +
find /tmp/bin/ -type l -name "*.db" -exec rm -i {} +

Finding and deleting broken symbolic links

Again, we use the find command:
find /dir/to/search/ -xtype l 
# add maxdepth to limit searching inside sub dir levels 
find /dir/to/search/ -maxdepth 1 -xtype l 
# Current dir
find . -maxdepth 1 -xtype l  -ls

Here is what I see from the last command:

 15597621      0 lrwxrwxrwx   1 vivek    vivek           3 Jun  3 16:37 ./bar -> foo

To remove that broken symlink, run:

find . -maxdepth 1 -xtype l  -delete
# Verify it
find . -maxdepth 1 -xtype l  -delete

Where find command options are:

  • -type l : Find only symbolic link
  • -lname "*.txt" :File is a symbolic link whose contents match shell pattern such as “*.txt”. Pass the -ilname "pattern" to the find for the case insensitive match. This option only works the latest version of GNU/find.
  • -print : Print matched file lists.
  • -delete : Remove/delete matched symlinks.
  • -exec rm -i {} + : Remove/delete matched symlinks using the rm command with confirmation
  • -xtype l : Deal with a symbolic link (find only symlinks).
  • -ls : List symbolic links if found.

Linux Remove Symbolic Link Command Options

Type the following command:
rm --help
unlink --help


You learned the rm and unlink command to delete or remove a symbolic link under Linux operating systems. See the rm/unlink command man page by typing the following man command or read it online here:
man rm
man find
man unlink

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 16 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
16 comments… add one
  • Veerabahu Jun 9, 2011 @ 6:34

    Is there any way to automatically delete the links too on deletion of a file
    mainfile -> linkfile
    now rm -f mainfile , should delete linkfile too ?? in RHEL it exists but points no where.

  • Srinivas Nov 23, 2011 @ 8:47

    Hi ,
    can you explain below thing

    [root@localhost html]# unlink bugzilla-st/
    unlink: cannot unlink `bugzilla-st/’: Not a directory
    [root@localhost html]#
    [root@localhost html]#
    [root@localhost html]# rm bugzilla-st/
    rm: cannot remove `bugzilla-st/’: Is a directory


    • L.Yao Dec 26, 2011 @ 6:18

      rm -R bugzilla-st/
      what`s the result?

  • nandeep Jun 12, 2012 @ 17:22

    dont put slash at the end, use “unlink bugzilla-st” then it will work even i ahd the same problem,

    • mschober Mar 1, 2013 @ 15:33

      thanks, the trailing slash was the issue for me too

  • Prasad Jayasinghe Jun 22, 2012 @ 6:10

    1st delete the source file..
    then remove the Link
    symlink file
    test 1–> /opt/test

    removing source file
    # rm -Rf /opt/test
    remove link
    # unlink test1

    enjoy……. :D

  • cac Jul 27, 2012 @ 4:07

    [root@localhost html]# unlink bugzilla-st/
    unlink: cannot unlink `bugzilla-st/’: Not a directory

    ==> unlink bugzilla-st

  • srinivas Dec 11, 2012 @ 6:38

    thanks All , After removing slash it is working .

  • TBotNik Sep 25, 2014 @ 16:53


    So how do you write a bash script to wipe all existing symlinks (unknown to you) and re-establish new ones?

    Would need special exceptions for system created symlinks necessary for OS functions



  • Renato Jun 18, 2015 @ 19:20

    I found out the hard way that “unlink” will not only remove symbolic links but will delete a file if you run “unlink” on an actual file instead of a symbolic link.

  • Ajju Jan 29, 2016 @ 9:12

    unlink will also remove the target file of a sym link if that is the only link and no one has opened the target (no open file descriptor). Lost 10 days of work in a zippy damn it :(

    Please mention this detail sir so others are saved from this pain like I am going through now :(

    • RENJU Feb 18, 2016 @ 7:13

      Ajju, it will not delete the target file.

      • Ajju Mar 8, 2016 @ 4:39

        I ran unlink on my softlink and the entire target file (which was a directory however a dir is also just a special kind of a file right?) got deleted.

        • milcza Mar 28, 2016 @ 21:50

          Ouch, sorry to hear that. :-(

          I’m experiencing exactly the same behavior on Fedora 22. Running the rm or ulink command on the symlink removes the content of the target directory, but the symbolic link stays unaffected. I can’t seem to be capable of figuring out why that is.

        • 🐧 Vivek Gite Mar 28, 2016 @ 22:41

          Don’t worry, rm or unlink doesn’t remove directories unless specifically told to do so. Also, rm/unlink doesn’t remove the target directory or file. You must have mixed options and deleted the target first. Here is an example to prove it:

          # create a dir
          mkdir foo
          # copy some file 
          cp /etc/resolv.conf foo
          # Create soft link
          ln -s foo bar
          # Verify it
          ls -ldi foo bar
          # Delete the link
          unlink bar
          # Verify it and foo should be there
          ls -li

          This is why you need to make regular backups. Mistakes happen at the CLI. Good luck!

  • Nadia Hanson Jun 3, 2021 @ 11:13

    I search for “how to delete symbolic links in linux” and found your tutorial. Very much helpful for new Linux developers. Teşekkür ederim.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum