How to Find the Path of an Executable Command in Linux

When you type a command like python, node, or grep into your Linux terminal, the operating system instantly runs the corresponding executable file. But how does the terminal know where that file is actually located on your hard drive? If you are troubleshooting a script or have multiple versions of a programming language installed, you often need to know the exact absolute path of the command you are running. You can easily find this using the which command.

Using the ‘which’ Command

The which utility searches through your system’s PATH environment variable to locate the exact binary file that will be executed when you type a specific word.

  1. Open your terminal application.
  2. Type the word which followed by a space and the command you want to locate.
    which python3
  3. Press Enter.

The terminal will instantly print out the full absolute path to the executable file, such as /usr/bin/python3. This guarantees you know exactly which version of the software your system is prioritizing.

Finding All Installed Versions

Sometimes, you might have a command installed in multiple locations (e.g., one in /usr/bin/ and a custom installation in /usr/local/bin/). To see every single instance of the command that exists in your PATH, you can use the -a flag:

which -a python3

This will output a list of all matching executables, helping you debug environment conflicts when a script refuses to run correctly.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.

Receive our best articles and tips delivered straight to your inbox.