xref: /freebsd/usr.bin/which/which.1 (revision ab393e9548f8cc0ee28499c411963b798ebb38a5)
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.Dd September 24, 2020
31.Dt WHICH 1
32.Os
33.Sh NAME
34.Nm which
35.Nd "locate a program file in the user's path"
36.Sh SYNOPSIS
37.Nm
38.Op Fl as
39.Ar program ...
40.Sh DESCRIPTION
41The
42.Nm
43utility
44takes a list of command names and searches the path for each executable
45file that would be run had these commands actually been invoked.
46.Pp
47The following options are available:
48.Bl -tag -width indent
49.It Fl a
50List all instances of executables found (instead of just the first one
51of each).
52.It Fl s
53No output, just return 0 if all of the executables are found, or 1 if
54some were not found.
55.El
56.Pp
57Some shells may provide a builtin
58.Nm
59command which is similar or identical to this utility.
60Consult the
61.Xr builtin 1
62manual page.
63.Sh EXAMPLES
64Locate the
65.Xr ls 1
66and
67.Xr cp 1
68commands:
69.Bd -literal -offset indent
70$ /usr/bin/which ls cp
71/bin/ls
72/bin/cp
73.Ed
74.Pp
75Same as above with a specific
76.Ev PATH
77and showing all occurrences:
78.Bd -literal -offset indent
79$ PATH=/bin:/rescue /usr/bin/which -a ls cp
80/bin/ls
81/rescue/ls
82/bin/cp
83/rescue/cp
84.Ed
85.Pp
86.Nm which
87will show duplicates if the same executable is found more than once:
88.Bd -literal -offset indent
89$ PATH=/bin:/bin /usr/bin/which -a ls
90/bin/ls
91/bin/ls
92.Ed
93.Pp
94Do not show output.
95Just exit with an appropriate return code:
96.Bd -literal -offset indent
97$ /usr/bin/which -s ls cp
98$ echo $?
990
100
101$ /usr/bin/which -s fakecommand
102$ echo $?
1031
104.Ed
105.Sh SEE ALSO
106.Xr builtin 1 ,
107.Xr csh 1 ,
108.Xr find 1 ,
109.Xr locate 1 ,
110.Xr whereis 1
111.Sh HISTORY
112The
113.Nm
114command first appeared in
115.Fx 2.1 .
116.Sh AUTHORS
117.An -nosplit
118The
119.Nm
120utility was originally written in Perl and was contributed by
121.An Wolfram Schneider Aq Mt wosch@FreeBSD.org .
122The current version of
123.Nm
124was rewritten in C by
125.An Daniel Papasian Aq Mt dpapasia@andrew.cmu.edu .
126