Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a two seperate files on my computer,

which execfile
/usr/local/bin/
/usr/bin/

so, i have two files with the same name in two different directories. How can I specify exactly which command to run?

Thanks.

share|improve this question

migrated from stackoverflow.com May 15 '10 at 9:58

This question came from our site for professional and enthusiast programmers.

6 Answers 6

you can specify the full path to the command when you run it type:

/usr/bin/execfile

or

/usr/local/bin/execfile

to run the exact file at that path

share|improve this answer
    
kthanks, is there a way to pick one of those commands the default one? –  colorfulgrayscale May 14 '10 at 4:46
6  
Yes, if you want /usr/bin/execfile to be the default one, make sure /usr/bin/ is before /usr/local/bin/ in your PATH shell environment variable. –  Bertrand Marron May 14 '10 at 4:48
    
@tusbar +1 for correct answer ;) –  Jacob May 14 '10 at 4:54
/usr/local/bin/execfile

or

/usr/bin/execfile
share|improve this answer

When trying to execute a command foo, foo is searched in the directories specified by the PATH environment variable, in the same order as they are specified. If you want to avoid this, type the full path to the executable.

Type this in a terminal:

echo $PATH

to see your actual PATH environment variable content.

For example, if you want to always execute first executables inside /bin, make sure /bin comes first inside $PATH. You can specify PATH in the .profile file in your home directory. So for the example above, edit the file and put this line at the end:

export PATH=/bin:$PATH

This will work only for your user. If you want to specify $PATH in a system-wide fashion (it will work for all users except for those who change it in their .profile), add the same line above in the file /etc/profile (you will need root privileges.)

Also remember that profile files are only parsed initially. This means that if you edit your personal .profile file, you will have to make your shell re-parse it. You can do this logging out and logging in again or otherwise typing:

source ~/.profile

For the system-wide change, type

source /etc/profile

This will make your current shell session re-parse the profile file. If you want your complete bootstrapped system to parse it again, I think you better restart your session.

Also remember that this may change if you use a shell other than bash.

You can find some interesting information inside the bash man page: http://linux.die.net/man/1/bash

See section "Command Execution".

share|improve this answer
    
BTW ask this on superuser.com –  Dom De Felice May 15 '10 at 9:56

Write an alias in ~/.profile:

alias execfile='/usr/local/bin/execfile'

After the next login the right version will be chosen automatically. Start the other ones with the full path.

share|improve this answer

also check for that if they both belongs to same file - like it may be link

ls -al /usr/bin
ls -al /usr/local/bin

and check whether they are linked together

if they are linked then u can execute any no-difference, else you have to specify full path

share|improve this answer
1  
That will show if they're symlinked (you'll see something like "/usr/bin/execfile -> /usr/local/bin/execfile" if they are). To see if they are hardlinked, use ls -li /usr/bin/execfile /usr/local/bin/execfile and compare their inode numbers. –  Dennis Williamson May 15 '10 at 13:57
/usr/local/bin/execfile

/usr/bin/execfile
share|improve this answer

Your Answer

 
discard

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