Linux: Search/Find Command

By Xah Lee. Date: .

Find Command Location

which cmd
Show full path of a command, useful for checking if a program is installed.

The which command search for the command in $PATH environment variable. If it returns nothing, it means the command is not in the $PATH, yet it may be installed somewhere.

Try echo $PATH. It is a list of dir paths. They are searched in order.

Find a file by name using locate

locate fname
Find a file by name (using the database see man updatedb). This is similar to find dir_paths -name "*fname*" but much faster.
updatedb
Update the database used by locate. (this is done automatically. Useful only if you just installed bunch of new commands.)

Show Type of Command

type cmd
Show if cmd is a shell built-in or standalone program. For example, type kill. The command type is a built-in bash command, not a standalone shell util. Try type type

Excutable files must have executable bits on. That is, the “x”. For example, type ls -l /usr/bin to see them. 〔see Linux: File Permission System