Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 re-installed ns2, but didn't delete a file from the filesystem with path:


So when I type on my terminal:

which ns

I get:


Instead of the path I have set which is:


This is in my home directory me. How should I delete the file in the filesystem with a similar name? The properties of this file says in permissions that I do not own this file, so I cannot change the permissions.

I can't run my tcl scripts if the path isn't set correctly and to set it, I need to delete the duplicate ns. How to get permission to delete? And how to delete it using my terminal?

share|improve this question
Can you sudo on this machine? – Digital Chris Mar 19 '14 at 13:44
yes i can sudo on this machine. – pythonspark Mar 19 '14 at 13:56
Then you can sudo rm /usr/bin/ns and even better sudo cp /home/me/ns-allinone-2.35/bin/ns /usr/bin – Digital Chris Mar 19 '14 at 13:59
@DigitalChris If ns depends on other files being in paths relative to it, or if it's a symlink or hardlink, the sudo cp ... line can break it and stop it from working. I don't know what ns is, but unless it's just that one binary (I highly doubt it from the allinone having a bin directory), that operation is not safe. – allquixotic Mar 19 '14 at 14:05
Uhh... how do you reconcile "yes I can sudo" with "I don't have permission" ? – Carl Witthoft Mar 19 '14 at 18:39

It isn't required that you delete the file /usr/bin/ns in order to make which and exec automatically execute /home/me/ns-allinone-2.35/bin/ns.

All you have to do is put /home/me/ns-allinone-2.35/bin on your $PATH prior to /usr/bin.

Here's the wrong way to do it:

export PATH="${PATH}:/home/me/ns-allinone-2.35/bin"

In this case, /usr/bin (by default on $PATH) will be earlier in the $PATH expansion than the one you want, so you'll execute /usr/bin/ns when you run ns or which ns.

Here's the right way to do it:

export PATH="/home/me/ns-allinone-2.35/bin:${PATH}"

Now, just typing ns or which ns will point to the one you want, without having to delete anything.

Update: If you want, to avoid modifying your $PATH in ~/.bashrc or similar, you can create a bash script wrapper around your tcl script that modifies the path first. Something like this:

export PATH="/home/me/ns-allinone-2.35/bin:${PATH}"
tcl ...

If you want to delete /usr/bin/ns anyway, and you do not have access to the root account or the ability to sudo (or to put yourself in the /etc/sudoers file), and /usr/bin/ns is owned by root and is not world-writable, then you are mostly out of options for deleting this file, unless:

  • You are able to boot the computer into another operating system (live CD, live USB, etc.), obtain root in that OS, and delete the file;
  • You execute some sort of exploit (I do not recommend this if you do not own the machine!)

Basically, "how do I delete a file I don't have permission to delete" is a loaded question: the question assumes that the owner of the machine wants you to delete this file, and wants to give you permission. If the owner of the machine isn't you, you should not be even asking this question, and we will not help you break or intrude into someone else's machine. It'd be like saying "how do I drive this car on the street when I don't have the keys?" -- yeah, good luck with that.

share|improve this answer
you mean that if i export PATH this way in my .bashrc file, my tcl script should work? because i dont want to export PATH everytime i run script after logging into terminal. i want to make path change permanent. – pythonspark Mar 19 '14 at 13:55
He really should remove that binary if he has no need to execute it from that directory anyhow, but I do agree with the rest of your assessment. Also, even if he did it the wrong way, which would show the other locations. – Daniel Chateau Mar 19 '14 at 13:56
You can indeed put it into your ~/.bashrc file; as long as you're only executing your tcl script as your user, you'll be fine. – allquixotic Mar 19 '14 at 13:57
@DanielChateau What implementation of which do you have? On my machines, which only ever shows the first instance of the found executable. So for instance if you had /usr/bin/bash and /usr/local/bin/bash, and both directories were on $PATH, it would only list the one that occurs **first** as a result of a path-search for the executable. Similarly, if you chmod -x` one of the instances, that instance will be "hidden" from which finding it. That's how it's always worked on my boxen.... – allquixotic Mar 19 '14 at 13:58
Updated answer with a little guide for how the OP might write a bash script wrapper for this without even having to modify their .bashrc. – allquixotic Mar 19 '14 at 14:03

Quick glance at my own /usr/bin/ shows that directory is owned by root. Assuming you can use sudo or su, either rm as root or use chown to change it to your username or group.

You can become root user by simply issuing the su command. In most terminals you'll see your prompt change from $ to a # indicating you're currently logged into the terminal as root. Make sure when you're done as root you exit out immediately as to not inadvertently issue other commands with such elevated access to the file system which could lead to you doing damage to your file system. From there you can use rm on /usr/bin/ns.

The safer route is to use the sudo command to allow for a command to be run as root for just that instance by issuing your rm command like so:

sudo rm /usr/bin/ns

share|improve this answer
how to use chown or rm as root, can you please elaborate a bit? will i be able to delete it this way? – pythonspark Mar 19 '14 at 14:04
I've updated my answer to address your comment. – Daniel Chateau Mar 19 '14 at 14:13
i did what u said and now after i type which ns, it gives me nothing. Is that a good sign? – pythonspark Mar 19 '14 at 23:00
That at least means you've removed ns from /usr/bin/ correctly, but you still need to follow what allquixotic noted in his answer to fully resolve your issue. – Daniel Chateau Mar 20 '14 at 14:28

@allquixotic is absolutely right. You can't delete a file if you don't have the permissions to do so and the only way would be to get the permissions by an exploit or by using something like sudo if you have the right. That's the whole point of filesystem permissions.

Now, another approach that you can use to get around this is to set up an alias. Open your shell's initialization file (~/.bashrc if you're using bash) and add this line:

alias ns='/home/me/ns-allinone-2.35/bin/ns'

Bash aliases are evaluated before the $PATH is searched so this will make the ns command point to your locally installed version by default.

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.