Linux Delete Symbolic Link ( Softlink )

by on August 15, 2006 · 9 comments· LAST UPDATED August 15, 2009

in , ,

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
Tweet itFacebook itG+ itDownload PDF versionFound an error/typo on this page?

{ 9 comments… read them below or add one }

1 Veerabahu June 9, 2011 at 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.


2 Srinivas November 23, 2011 at 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



3 L.Yao December 26, 2011 at 6:18 am

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


4 nandeep June 12, 2012 at 5:22 pm

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


5 mschober March 1, 2013 at 3:33 pm

thanks, the trailing slash was the issue for me too


6 Prasad Jayasinghe June 22, 2012 at 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


7 cac July 27, 2012 at 4:07 am

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

==> unlink bugzilla-st


8 srinivas December 11, 2012 at 6:38 am

thanks All , After removing slash it is working .


9 TBotNik September 25, 2014 at 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




Leave a Comment

Tagged as: , , , , , , , ,

Previous Faq:

Next Faq: