Linux Delete Symbolic Link ( Softlink )

by Vivek Gite on August 15, 2006 · 3 comments

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

Outputs:

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

Now delete dns symbolic link:

 
rm dns

OR

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

OR

unlink test

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 3 comments… read them below or add one }

1 Veerabahu June 9, 2011

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

Reply

2 Srinivas November 23, 2011

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

Thanks&Regards,
Srinu

Reply

3 L.Yao December 26, 2011

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

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 7 + 4 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: