xref: /freebsd/usr.bin/which/which.1 (revision 7ef62cebc2f965b0f640263e179276928885e33d)
1.\" Manpage Copyright (c) 1995, Jordan Hubbard <jkh@FreeBSD.org>
2.\"
3.\" Redistribution and use in source and binary forms, with or without
4.\" modification, are permitted provided that the following conditions
5.\" are met:
6.\" 1. Redistributions of source code must retain the above copyright
7.\"    notice, this list of conditions and the following disclaimer.
8.\" 2. Redistributions in binary form must reproduce the above copyright
9.\"    notice, this list of conditions and the following disclaimer in the
10.\"    documentation and/or other materials provided with the distribution.
11.\" 3. All advertising materials mentioning features or use of this software
12.\"    must display the following acknowledgement:
13.\"      This product includes software developed by the FreeBSD Project
14.\"      its contributors.
15.\" 4. Neither the name of the FreeBSD Project nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTOR ``AS IS'' AND ANY EXPRESS OR
20.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22.\" IN NO EVENT SHALL THE CONTRIBUTOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28.\" OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29.\"
30.\" $FreeBSD$
31.\"
32.Dd September 24, 2020
33.Dt WHICH 1
34.Os
35.Sh NAME
36.Nm which
37.Nd "locate a program file in the user's path"
38.Sh SYNOPSIS
39.Nm
40.Op Fl as
41.Ar program ...
42.Sh DESCRIPTION
43The
44.Nm
45utility
46takes a list of command names and searches the path for each executable
47file that would be run had these commands actually been invoked.
48.Pp
49The following options are available:
50.Bl -tag -width indent
51.It Fl a
52List all instances of executables found (instead of just the first one
53of each).
54.It Fl s
55No output, just return 0 if all of the executables are found, or 1 if
56some were not found.
57.El
58.Pp
59Some shells may provide a builtin
60.Nm
61command which is similar or identical to this utility.
62Consult the
63.Xr builtin 1
64manual page.
65.Sh EXAMPLES
66Locate the
67.Xr ls 1
68and
69.Xr cp 1
70commands:
71.Bd -literal -offset indent
72$ /usr/bin/which ls cp
73/bin/ls
74/bin/cp
75.Ed
76.Pp
77Same as above with a specific
78.Ev PATH
79and showing all occurrences:
80.Bd -literal -offset indent
81$ PATH=/bin:/rescue /usr/bin/which -a ls cp
82/bin/ls
83/rescue/ls
84/bin/cp
85/rescue/cp
86.Ed
87.Pp
88.Nm which
89will show duplicates if the same executable is found more than once:
90.Bd -literal -offset indent
91$ PATH=/bin:/bin /usr/bin/which -a ls
92/bin/ls
93/bin/ls
94.Ed
95.Pp
96Do not show output.
97Just exit with an appropriate return code:
98.Bd -literal -offset indent
99$ /usr/bin/which -s ls cp
100$ echo $?
1010
102
103$ /usr/bin/which -s fakecommand
104$ echo $?
1051
106.Ed
107.Sh SEE ALSO
108.Xr builtin 1 ,
109.Xr csh 1 ,
110.Xr find 1 ,
111.Xr locate 1 ,
112.Xr whereis 1
113.Sh HISTORY
114The
115.Nm
116command first appeared in
117.Fx 2.1 .
118.Sh AUTHORS
119.An -nosplit
120The
121.Nm
122utility was originally written in Perl and was contributed by
123.An Wolfram Schneider Aq Mt wosch@FreeBSD.org .
124The current version of
125.Nm
126was rewritten in C by
127.An Daniel Papasian Aq Mt dpapasia@andrew.cmu.edu .
128