WHICH(1)
๐ธ WHICH(1) โ like, the manual page for which, bestie ๐
okay so real talk: this is the WHICH(1) page from the General Commands Manual, and it's genuinely one of the most underrated little tools ever. no cap. let's get into it ๐ซถ
โจ NAME โจ
which โ shows the full path of (shell) commands. that's it. that's the vibe. ๐
๐ฆ SYNOPSIS ๐ฆ
which [options] [--] programname [...]
๐ DESCRIPTION ๐
So which takes one or more arguments, right? For each of its arguments it prints to stdout the full path of the executables that would have been executed when this argument had been entered at the shell prompt. like, it's the "where does this even live" detective ๐
It does this by searching for an executable or script in the directories listed in the environment variable PATH, using the same algorithm as bash(1). same algorithm, icon behavior. ๐
little meta moment: this man page is generated from the file which.texinfo. yes bestie, the docs have docs.
โจ OPTIONS โจ
--all,-aโ print all matching executables inPATH, not just the first. giving "i want the whole roster" energy ๐--read-alias,-iโ read aliases from stdin, reporting matching ones on stdout. this is useful in combination with using an alias forwhichitself. for example
alias which=โalias | which -iโ.
--skip-aliasโ ignore option--read-alias, if any. this is useful to explicitly search for normal binaries, while using the--read-aliasoption in an alias or function forwhich. ๐--read-functionsโ read shell function definitions from stdin, reporting matching ones on stdout. this is useful in combination with using a shell function forwhichitself. for example:
which() { declare -f | which --read-functions "$@" }
export -f which
--skip-functionsโ ignore option--read-functions, if any. this is useful to explicitly search for normal binaries, while using the--read-functionsoption in an alias or function forwhich. ๐--skip-dotโ skip directories inPATHthat start with a dot. ๐ซ--skip-tildeโ skip directories inPATHthat start with a tilde and executables which reside in theHOMEdirectory. ๐--show-dotโ if a directory inPATHstarts with a dot and a matching executable was found for that path, then print./programnamerather than the full path. cute lil shorthand โจ--show-tildeโ output a tilde when a directory matches theHOMEdirectory. โ ๏ธ heads up: this option is ignored whenwhichis invoked as root. sorry root girlies.--tty-onlyโ stop processing options on the right if not on tty. ๐--version,-v,-Vโ print version information on standard output then exit successfully. ๐--helpโ print usage information on standard output then exit successfully. the classic ๐
๐ฅ RETURN VALUE ๐ฅ
which returns the number of failed arguments, or -1 when no programname was given. so like, the exit code is literally telling you how many of your little guesses flopped. it's giving report card. ๐ญ
๐ธ EXAMPLE ๐ธ
The recommended way to use this utility is by adding an alias (C shell) or shell function (Bourne shell) for which like the following:
[ba]sh:
which ()
{
(alias; declare -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot "$@"
}
export -f which
[t]csh:
alias which โalias | /usr/bin/which --tty-only --read-alias --show-dot --show-tildeโ
This will print the readable ~/ and ./ when starting which from your prompt, while still printing the full path when used from a script:
> which q2
~/bin/q2
> echo $(which q2)
/home/carlo/bin/q2
the way that last one just works โ script mode gets the full path, prompt mode gets the cute version. main character energy fr fr ๐
๐ BUGS ๐
okay, the not-so-slay parts:
The HOME directory is determined by looking for the HOME environment variable, which aborts when this variable doesn't exist. so if HOME ghosts you, which ghosts everyone. ๐ญ
And which will consider two equivalent directories to be different when one of them contains a path with a symbolic link. lowkey rude but that's the behavior, no cap.
๐ AUTHOR ๐
Carlo Wood <carlo@gnu.org> โ legend behavior, we stan ๐ซถ
โญ SEE ALSO โญ
and that's the whole page bestie!! ๐ you just read the WHICH(1) manual page from the General Commands Manual โ no version number or date to be found, so consider this your cute little sign-off instead: go forth, find your binaries, and remember that HOME not existing will absolutely ruin your whole day. mwah ๐โจ
๐ฆ where this page comes from
- arch rolling: which 2.25-1 ยท GPL-3.0-or-later
- fedora 44: which 2.25-1.fc44 ยท GPL-3.0-only
- nixpkgs unstable: which 2.25
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms