Skip to content
Mon, Oct 31 2005

HOWTO: Remove a Symbolic Link

This may seem not seem complicated, but if you don’t know, you don’ t know.

When you create a symbolic link, the link file you’ve created just points to the target file. Therefore, the link file has no other purpose in life than that. So, when you want to get rid of it, just delete the link file.

Done.

Around The Web
Share This Post:
  • Digg
  • email
  • Facebook
  • StumbleUpon
  • Tumblr
Technology

Comments

  1. By Pothi Kalimuthu

    Thanks for sharing. The trailing slash wasted around 10 minutes of my time. :) Learned a lesson. ;-)

  2. By Lucas

    Thanks again, Karl!

  3. By Michael

    Maybe if ‘English’ takes some serious meds he/she might get some friends? What a hickhead.

  4. By B

    Thanks Jon. The issue for me was I wanted to make sure doing “rm” on the sym link didn’t harm the actual target of the link.

  5. By Ben

    Thanks, for some reason I was scared the remove might delete the target file!

  6. By Charlie

    on FC6 at least, your cwd has to be the directory in which the link was created for rm link to work.

    this is implied by whitehorn’s post..

  7. By BartO

    Ok, symbolic links are just really weird. Not only the rm -rf command follows the link, just rm seems to do it as well. That is, it doesn’t do anything for it thinks the link is a dirictory, and non-empty directories can’t be removed by just rm. But when I delete the link by pushing shift-del in nautilus, the link is removed whitout doing harm to the directory it pointed to. Both are done as root. I don’t get it…

  8. By Hoaobrook

    JON, thanks for posting. I preferred the unlink method as any RM commands have to be validated by the administrator here – why? we had a newbie accidently run an rm -rf from root :( – at any rate, good on ya for posting this helpful bit. I was a little worried about running rm on the link thinking it might follow the link and delete the files ( I had the link on a folder).

  9. By Hoaobrook

    English, you sound like a frustrated English teacher. I imagine you’ve spent many a days grading sub-par English papers, likely just before this post. I understand your frustration, however, publicly scorning the original poster for sharing knowledge is not the most efficient way of becoming part of a community online.

    If you re-read your posting, you will see how you failed to tackle the true nature of the post.

  10. By English

    In English, you’ve effectively said nothing:

    “When you create a symbolic link, the link file you’ve created just points to the target file. Therefore, the link file has no other purpose in life than that. So, when you want to get rid of it, just delete the link file.”

    The point is the last it in the paragraph. The preceding sentence references the link file points to the target file. If you want to get rid of it…

    The it could mean either the target file, in which case you are stating that you can remove targetfiles by removing symlinks, or removing the symlink, the desired behavior.

    The correct way to write this in English is not to use ‘it’. While there is a ‘correct’ way of interpreting *it*, all style books point to not using it, and referring to the noun.

    “When you create a symbolic link, the link file you’ve created just points to the target file. Therefore, the link file has no other purpose in life than that. So, when you want to get rid of the symbolic link, just delete the link file. This will not delete the target file.”

    Now, I’ve used two precedents here. I’ve gone for plain English, but in addition, I’ve used tenets of technical writing, where you answer a question rather than state a fact.

    The additional sentence answers the question in a users mind, and completes the thought process.

    If you re-read your posting, you will see how you failed to tackle the true nature of the post.

  11. By jesblanc

    hello all,

    maybe someone can help me here.

    i created a symlink, which points the website store.islandcargosystems.com to icsmarketplace.com. it works great except that i cannot understand why it kills the links on my flash file.

    anybody know anything about this? im thinking of going a different route and creating a mod_rewrite.

    thanks in advance

  12. By Farhan

    thanks bbobbo ur tip solved my problem.

  13. By Mike_S

    The tab-completion-trailing-slash was also the problem with my attempts to rm / unlink the sym links.

    .. spoiled by the tab completion :) .. though it really is a neccessary and vital shell tool when navigating the typical mult/levelled/directory/structure/found/in/most/unix/applications !

  14. By jack oniel

    Saved my bacon with the unlink command, thanks!

  15. By adam

    nice resource you have here … I had problems with deleting the symbolic link too – unlink wasn’t working. Until one reader mentioned the tab completion was adding the trailing slash indicating it is a directory … this finally worked … unlink name_pointing_to_a_directory BUT DON’T ADD THE TRAILING SLASH.

    :)

  16. By david

    If I run a program when my shell is at its directory, it runs fine. But if I run it via the symbolic link, the program itself complains about not finding some files. I wonder if running a symbolic link is “as if” running the program from where its directory is at – in my case, not!? How do I run my program from any location I want (btw, I stored the symbolic link in a directory opt/bin which is a existing PATH. My other symbolic links are in the opt/bin too and they run fine. Only this one program “ClustalX” cannot find things … )

    Help, thanks!

  17. By Ed

    I’m having an issue with creating a link Too many levels of symbolic links, how do I fix this?

  18. By Zander Chance

    Thanks bbobbo, you have no idea how long that’s been bugging me! I had a few directories laying around that I couldn’t delete because of those stupid symbolic links, but now all is well! :)

  19. By F4jr

    Thanks, this can avoid some mistakes !