Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am working on my project using network simulator2. I installed it and everything is fine. I attempted to create a symbolic link between this installation and /usr/bin, so I could invoke the software by running ns from the command-line. Namely, I ran:

sudo ln -s /home/vinaychalluru/ns-allinone-2.34/ns-2.34/ns /usr/bin/ns

which generated the following output:

ln: creating symbolic link '/usr/bin/ns': File exists

How can I delete the already created symlink or can I replace it with any other commands?

share|improve this question
I was trying to do sudo ln -s destination source, and of course it bugged. Thanks for the answer. – aviggiano Jun 7 '13 at 21:59
up vote 23 down vote accepted
sudo rm -r /usr/bin/ns

sudo ln -s /home/vinaychalluru/ns-allinone-2.34/ns-2.34/ns /usr/bin/ns
share|improve this answer
the above fails if ns is a folder - in which case use the rm -rf (recursive force switches) - in which case you might as well use the -sf switches for ln. – finley Nov 15 '10 at 13:26
@finley Yes, you are right. Incase ns is a folder, it can't be deletd. It is now ambiguos to me that, can we create a symbolic link to a folder.? – Vinay Challuru Nov 15 '10 at 13:41
yes, we can create a symbolic link to a folder. If it's a folder, you can do: sudo rm -r /usr/bin/ns – Paweł Karpiński Nov 15 '10 at 13:54
@Pawel I created a symlink to folder succesfully. I can even remove as u said above. But, when i type fold [created symlink for a folder] name in terminal it gives an error. What i actually thought was by creating a symlink to a folder and just typing the link name terminal would open that in nautilus. I am not sure whether it is possible or not..? – Vinay Challuru Nov 16 '10 at 5:16
@Vinaychalluru if you want to open that folder, try typing: cd fold - it will open in a terminal. If you want to open it in nautilus, type: nautilus fold – Paweł Karpiński Nov 16 '10 at 6:13

ln has an -f switch that 'forces' a sym link to be created whether it exists or not.

sudo ln -sf /home/vinaychalluru/ns-allinone-2.34/ns-2.34/ns /usr/bin/ns
share|improve this answer

I tried ln -sf while replacing but it didn't work for me, but doing ln -sfn directory link_name as root worked.

share|improve this answer
Thanks! The -n switch helped! – Slava Fomin II Mar 1 '15 at 18:55
Without -n I was getting an infinite loop problem. Thanks! – Christopher Markieta Dec 16 '15 at 0:18

To add to all answers above, a symbolic link can be treated as a regular file in many cases (the link, not the target).

rm on a symbolic link will remove it. If the link is owned by root, you will need to sudo.

You should be able to rm /usr/bin/ns or rather sudo rm /usr/bin/ns don't forget ownership.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.