≡ Menu

Linux Delete Symbolic Link ( Softlink )

How do I delete softlink or symbolic link in Linux operating system using a command prompt?

You can use any one of the following command to remove symbolic links:

  • rm – removes each given FILE including symbolic links
  • unlink – deletes a single specified file name including symbolic links.

Delete Symbolic Link File

Use the following syntax:

rm linkname
unlink linkname

Cd to /tmp

cd /tmp
ln -s /etc/resolv.conf dns
ls -l dns


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

Now delete dns symbolic link:

rm dns


unlink dns

Delete Symbolic Link Directory

Use the following syntax:

rm linkDirName
unlink linkDirName

Note: Avoid appending / at the end of linkDirName. Cd to /tmp:

cd /tmp
ln -s /etc test
ls -l test

Sample Output:

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

Now delete test symbolic link directory:

rm test


unlink test
Share this tutorial on:
{ 15 comments… add one }
  • VeerabahuJune 9, 2011, 6:34 am

    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.

  • SrinivasNovember 23, 2011, 8:47 am

    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.YaoDecember 26, 2011, 6:18 am

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

  • nandeepJune 12, 2012, 5:22 pm

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

    • mschoberMarch 1, 2013, 3:33 pm

      thanks, the trailing slash was the issue for me too

  • Prasad JayasingheJune 22, 2012, 6:10 am

    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

  • cacJuly 27, 2012, 4:07 am

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

    ==> unlink bugzilla-st

  • srinivasDecember 11, 2012, 6:38 am

    thanks All , After removing slash it is working .

  • TBotNikSeptember 25, 2014, 4:53 pm


    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



  • RenatoJune 18, 2015, 7:20 pm

    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.

  • AjjuJanuary 29, 2016, 9:12 am

    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 :(

    • RENJUFebruary 18, 2016, 7:13 am

      Ajju, it will not delete the target file.

      • AjjuMarch 8, 2016, 4:39 am

        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.

        • milczaMarch 28, 2016, 9:50 pm

          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 GiteMarch 28, 2016, 10:41 pm

          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. Goodluck!

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: , , , , , , , ,