For example, I have git
installed on my system.
But I don't remember where I installed it, so which command is fit to find this out?

- 52,586

- 2,385
5 Answers
If it is in your path, then you can run either type git
or which git
. The which
command has had problems getting the proper path (confusion between environment and dot files). For type
, you can get just the path with the -p
argument.
If it is not in your path, then it's best to look for it with locate -b git
It will find anything named 'git'. It'll be a long list, so might be good to qualify it with locate -b git | fgrep -w bin
.

- 22,536
-
16I use
locate
endlessly (it is very fast), but for those unaware of it,locate
is only as up to date as its most recent database update, which is automatically run daily on my Ubuntu. The refresh command issudo updatedb
... Alsolocate
has built-in regex capability, so commands like this works:locate -br "^git$"
... -bmeans restrict the search to just the *basename* ... or without the
-b`, it searches the full pathname .. Also, it only searches paths you have configured it to search.. there is no command-line control of this other than your regex filters. – Peter.O Jan 07 '12 at 21:24 -
9Prefer
type
towhich
.which
easily gets confused. – Gilles 'SO- stop being evil' Jan 07 '12 at 23:38 -
@Gilles, that's funny for me the behavior is exactly the opposite:
type
is a shell builtin that tells me aliases and such, andwhich
is an external program that shows me the path to an executable... although if there's a builtin that gets in the way that executable won't get called. – quodlibetor Jan 10 '12 at 21:37 -
@quodlibetor The problems with
which
are that it doesn't know about shell built-ins and functions (which is relevant when you're wondering what typing the command will do), and it uses a different$PATH
on some systems. – Gilles 'SO- stop being evil' Jan 10 '12 at 21:42
The POSIX standard way to do this is command -v git
. All UNIX-like systems should support this.

- 1,476
-
1In
zsh
, this will printalias ls=...
ifls
is aliased. IMHO the OP was looking for something to produce/usr/bin/ls
. – Tom Hale Jan 12 '22 at 08:24
whereis git
and you get the path to the command.
that is just if the git is in you PATH variable, in case you have installed it not through you package manager, it is more complex and you should use the find
or locate
commands.

- 5,771
-
1
-
5@Nikhil
type
, rather, notwhich
. See How to usewhich
on an aliased command? – Gilles 'SO- stop being evil' Jan 07 '12 at 23:39
The other answers here seem to be largely geared towards modern versions of Linux, so if you happen to use git
on an OS that doesn't have locate
, whereis
, which
, or apropos
(like Solaris, HPUX, etc), then there is always the old standby find
.
find / -name git
One some older versions of the systems listed above, you may need a -print
option supplied to find
.
find / -name git -print
And if you do use locate
, make sure you run updatedb
periodically. (locate.updatedb
on some BSD derivatives)

- 19,697
-
9For programs in the path, use
type
; it's reliable and portable (except to 30-year old systems). – Gilles 'SO- stop being evil' Jan 07 '12 at 23:40 -
1Thanks, @Gilles. I never knew about
type
. :) That's definitely going in the repertoire! – Tim Kennedy Jan 09 '12 at 15:20 -
It's probably worth pointing out that
find
does a full depth-first search of the file system starting from wherever you root it. Sofind / -name git
will traverse your whole system. If you know that the program is on your path you can usually doIFS=":"; path=$PATH; set $path; for dir in $path; do find $dir -name git; done
, although Unix filesystems are permissive enough that this can break in a variety of ways if have weird characters in yourPATH
. – quodlibetor Jan 09 '12 at 23:18 -
Actually the command I gave previously will break your
PATH
, the correct thing (with the same caveats as before) isIFS=":"; for dir in $PATH; do find "$dir" -name git; done
. Also, to reiterate, this answer should only be used by people who don't have access totype
orwhich
orlocate
, ie, almost nobody. @Arcege's answer is correct. – quodlibetor Jan 10 '12 at 21:34
To get the path to the installed program you either use whereis
or which
. If you happen to forget it's name, you can useapropos
with a synonym or description of your utility, e.g. apropos "version control"
will find git
. Following that is of course the whatis
command to briefly summarize the function of a program. This does however not apply to all programs and functions on your system. Try for instance whatis "the meaning of life, universe and everything"
.
which
command" indeed :) – Tikhon Jelvis Jan 08 '12 at 00:31command -v
andwhich
worked in Linux Alpine 3.16.2 (Docker image).whereis
andlocate
did not - not installed. – Artfaith Sep 17 '22 at 12:10