When you execute a standard shell command like python3 or gcc on a Linux server, the kernel rapidly scans the directories listed in your $PATH variable to locate the executable binary. If you have multiple versions of Python installed across different directories (e.g., /usr/bin/python3 vs. /usr/local/bin/python3), mathematically proving exactly which binary the system is prioritizing becomes critical for debugging. To force the Linux kernel to reveal the absolute, physical file path of the executable it intends to run, you must use the which command.
Executing the Path Trace
The which command is a deeply focused path interrogation engine. It does not execute the target program; it algorithmically simulates the exact search pattern the bash shell would use, and instantly reports the first match.
To interrogate the system’s routing for the Python interpreter, open your terminal and type:
which python3
The exact millisecond you press Enter, the engine scans the $PATH matrix from left to right. If it locates a valid executable, it outputs the absolute physical path to standard output (e.g., /usr/bin/python3). If the command mathematically does not exist anywhere in the authorized path, the engine will output nothing and violently return a non-zero exit status code.
Executing a Deep Matrix Scan
By default, the engine stops scanning the exact millisecond it finds the first valid match. However, if you are attempting to clean up a chaotic server environment, you may need to map every single instance of the executable hidden across the file system.
To force the engine to scan the entire path matrix and output all matches, inject the -a (all) flag:
which -a python3
The engine will now output a vertical list of every single path containing that specific executable binary. This allows you to mathematically prove if a rogue, outdated installation in /opt/ is conflicting with the pristine system package in /bin/.