Find command location inside or outside of path
Assume you want to find the location of
uname, a program that lists system information. If you want to know what directory the top level command is stored in you have a number of options:
$ which uname
$ type -a uname
uname is /bin/uname
$ command -v uname
$ locate uname
(... SNIP dozens of Windows files on C & D ...)
The last option
locate returns all files containing
uname not just the program that is run from the command prompt.
The advantage of
locate is it will find commands not in your search path.
type -a (preferred over simple
which will only find commands in your search path. To see your search path use
Take for example this answer in How to start screencloud? :
locate screencloud command will find it but
which screencloud and
type -a screencloud will not because:
- The full name is
screencloud.sh and only
locate command searches on partial match.
/opt/screencloud probably isn't in the search path.
type only look for executable files in search path.
Note: This is an older answer. Modern ScreenCloud is called with
Locate's advantage over the
find command is it can be hundreds or even thousands of times faster. Also running
find starting from
/ will give many permission errors you won't experience with
If you just installed the program today you will need to use
sudo updatedb to update locate's database.