2

I have a two separate 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?

0

6 Answers 6

9

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

3
  • kthanks, is there a way to pick one of those commands the default one?
    – colorfulgrayscale
    May 14, 2010 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. May 14, 2010 at 4:48
  • @tusbar +1 for correct answer ;)
    – Jacob
    May 14, 2010 at 4:54
1
/usr/local/bin/execfile

or

/usr/bin/execfile
1

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".

1
  • BTW ask this on superuser.com
    – Dom De Felice
    May 15, 2010 at 9:56
1

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.

1

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

1
  • 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. May 15, 2010 at 13:57
0
/usr/local/bin/execfile

/usr/bin/execfile

You must log in to answer this question.