Here's a hypothetical situation....There are two binaries with the same name. Lets call them charles. One charles is in the /usr/bin/ directory and the other charles is in ~/bin/. Assuming that ~/bin/ is included in the execution path, which charles will be executed when the charles command is called?

  • In addition to the answers, don't forget that you can always prefix the command with the full path in order to select the binary you want to run. Doing so will override the order given in $PATH. (Yes, I know this is more than a comment but was deleted as an answer. I hope it helps.)
    – Latkar
    Feb 19, 2022 at 7:36

2 Answers 2


If issued just the command it will be the one that is found first in your $PATH. If you do

echo $PATH

you get the path that is used to find an executable...


If ~/bin/

  • is NOT in $PATH it wont be found.
  • is before /usr/bin/ the one in ~/bin/ is used;
  • is behind /usr/bin/ the one in /usr/bin/ is used;

Extra exception:

If you are in the ~/bin/ directory and do ./charles the one in ~/bin/ will be executed.

  • If in a build environment, where in the chain are new paths added?
    – leszakk
    Jan 10, 2015 at 23:31

This really depends on where /usr/bin and /bin and ~/bin are in the exported PATH variable.


 -----> charles will be found in /usr/bin and used from there

 -----> in this case charles will be found first in the users' bin 
        and used from there
  • Where is the path variable stored?
    – leszakk
    Jan 10, 2015 at 23:23
  • There are several places. Have a look at /etc/login.defs and search for ENV_PATH. You'll find the minimal value for every user logged into the system. In addition you can check ~/.profile, /etc/profile and some of the flles under /etc/profile.d/. You'll find too that there's a value for PATH (and maybe others environment variables) hardcoded inside the bash ELF itself.
    – Latkar
    Feb 23, 2022 at 18:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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