The Binary Location Vector
When you type a command like python or docker into an Ubuntu terminal, you do not need to specify exactly where that program is located on the hard drive. The operating system uses the system $PATH variable to automatically hunt down the correct executable file and run it. However, if you are writing complex automation scripts, or if you have multiple conflicting versions of the same software installed (e.g., Python 2 and Python 3), you must definitively know the absolute path of the binary being executed.
How to Find the Path of an Executable
Linux provides two primary command-line tools designed specifically to interrogate the system and locate application binaries.
1. Open your terminal application or connect to your server via SSH.
2. The which command: This is the most surgical tool. It tells you exactly which binary the system will execute if you type a command. For example, to find where the python3 executable lives, type:
which python3
3. The terminal will immediately output the absolute path, such as /usr/bin/python3. You can now confidently paste this exact path into your bash scripts.
4. The whereis command: If you need a broader overview, this tool is superior. It locates the binary, but it also hunts down the source code and the official manual (man) pages associated with the command. Type:
whereis python3
5. The terminal will output a string containing multiple locations, such as python3: /usr/bin/python3 /usr/lib/python3 /etc/python3 /usr/share/man/man1/python3.1.gz. The first path listed is almost always the primary executable.
By utilizing these tools, you eliminate all ambiguity regarding which version of a software package your server is actually utilizing.