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
/bin/uname
$ type -a uname
uname is /bin/uname
$ command -v uname
/bin/uname
$ locate uname
/bin/uname
(... SNIP dozens of Windows files on C & D ...)
/usr/lib/klibc/bin/uname
/usr/lib/plainbox-provider-resource-generic/bin/uname_resource
/usr/share/man/man1/uname.1.gz
/usr/share/man/man2/oldolduname.2.gz
/usr/share/man/man2/olduname.2.gz
/usr/share/man/man2/uname.2.gz
Locate advantages
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 type
) and which
will only find commands in your search path. To see your search path use echo $PATH
.
Take for example this answer in How to start screencloud? :
Try...
/opt/screencloud/screencloud.sh
The 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. which
and type
only look for executable files in search path.
Note: This is an older answer. Modern ScreenCloud is called with screencloud
.
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 locate
.
Locate disadvantages
If you just installed the program today you will need to use sudo updatedb
to update locate's database.
.deb
package but you need to add PPA.screencloud.sh
toscreencloud
and suspected it was moved out of/opt
. That part of my answer was pointing out howtype
andwhich
wouldn't findscreencloud
butlocate
would.screencloud.sh
actually still exists but I am not sure how it differs fromscreencloud
other than the fact that the.sh
file is a script andscreencloud
is not. I really am not familiar with this application. Under/usr/bin/
there is ascreencloud
, ascreencloud.sh
, and also ascreencloud-
followed by the version number sort of like howgimp
is.