How to find the full path to a program, why a command isn’t found, and which package a file comes from.
command -v php
/usr/bin/phpcommand -v name | the path to the program that will run under this name; works in any shell and is handy in scripts |
which -a name | every program with this name, in the order the system searches for them |
type name | tells you if the name is not a program but an alias or a built-in shell command |
whereis name | where the program and its manual page are located |
Why a command isn’t found
Programs are searched for in the directories listed in the PATH variable; to see it, run echo $PATH. If a program is installed but you get “command not found”, its directory is not in PATH: run it by its full path or add the directory to PATH. For the same reason, it is best to always use full paths in cron — it has its own short PATH.
To find a program file anywhere on the disk: sudo find / -name 'name' -type f 2>/dev/null.
Which package a file comes from
| Ubuntu, Debian | dpkg -S /usr/bin/php |
| AlmaLinux | rpm -qf /usr/bin/php |
| FreeBSD | pkg which /usr/local/bin/php |
Didn’t find the answer? Ask our support team — we’ll help.