Initial import from FreeBSD RELENG_4:
[dragonfly.git] / usr.bin / locate / locate / locate.1
1 .\" Copyright (c) 1995 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
2 .\" Copyright (c) 1990, 1993
3 .\"     The Regents of the University of California.  All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\"    notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\"    notice, this list of conditions and the following disclaimer in the
12 .\"    documentation and/or other materials provided with the distribution.
13 .\" 3. All advertising materials mentioning features or use of this software
14 .\"    must display the following acknowledgement:
15 .\"     This product includes software developed by the University of
16 .\"     California, Berkeley and its contributors.
17 .\" 4. Neither the name of the University nor the names of its contributors
18 .\"    may be used to endorse or promote products derived from this software
19 .\"    without specific prior written permission.
20 .\"
21 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .\" SUCH DAMAGE.
32 .\"
33 .\"     @(#)locate.1    8.1 (Berkeley) 6/6/93
34 .\" $FreeBSD: src/usr.bin/locate/locate/locate.1,v 1.16.2.5 2002/07/08 21:31:28 trhodes Exp $
35 .\"
36 .Dd June 6, 1993
37 .Dt LOCATE 1
38 .Os
39 .Sh NAME
40 .Nm locate
41 .Nd find filenames quickly
42 .Sh SYNOPSIS
43 .Nm
44 .Op Fl Scims
45 .Op Fl l Ar limit
46 .Op Fl d Ar database
47 .Ar pattern ...
48 .Sh DESCRIPTION
49 The
50 .Nm
51 program searches a database for all pathnames which match the specified
52 .Ar pattern  .
53 The database is recomputed periodically (usually weekly or daily),
54 and contains the pathnames
55 of all files which are publicly accessible.
56 .Pp
57 Shell globbing and quoting characters
58 .Dq ( * ,
59 .Dq \&? ,
60 .Dq \e ,
61 .Dq \&[
62 and
63 .Dq \&] )
64 may be used in
65 .Ar pattern  ,
66 although they will have to be escaped from the shell.
67 Preceding any character with a backslash
68 .Pq Dq \e
69 eliminates any special
70 meaning which it may have.
71 The matching differs in that no characters must be matched explicitly,
72 including slashes
73 .Pq Dq / .
74 .Pp
75 As a special case, a pattern containing no globbing characters
76 .Pq Dq foo
77 is matched as though it were
78 .Dq *foo* .
79 .Pp
80 Historically, locate only stored characters between 32 and 127.  The
81 current implementation store any character except newline
82 .Pq Sq \en
83 and NUL
84 .Pq Sq \e0 .
85 The 8-bit character support doesn't waste extra space for
86 plain ASCII file names.
87 Characters less than 32 or greater than 127
88 are stored in 2 bytes.
89 .Pp
90 The following options are available:
91 .Bl -tag -width 10n
92 .It Fl S
93 Print some statistic about the database and exit.
94 .It Fl c
95 Suppress normal output; instead print a count of matching file names.
96 .It Fl d Ar database
97 Search in
98 .Ar database
99 instead the default file name database.
100 Multiple
101 .Fl d
102 options are allowed.  Each additional
103 .Fl d
104 option adds the specified database to the list
105 of databases to be searched.
106 .Pp
107 The option
108 .Ar database
109 may be a colon-separated list of databases.
110 A single colon is a reference
111 to the default database.
112 .Bd -literal
113 $ locate -d $HOME/lib/mydb: foo
114 .Ed
115 .Pp
116 will first search string
117 .Dq foo
118 in
119 .Pa $HOME/lib/mydb
120 and then in
121 .Pa /var/db/locate.database .
122 .Bd -literal
123 $ locate -d $HOME/lib/mydb::/cdrom/locate.database foo
124 .Ed
125 .Pp
126 will first search string
127 .Dq foo
128 in
129 .Pa $HOME/lib/mydb
130 and then in
131 .Pa /var/db/locate.database
132 and then in
133 .Pa /cdrom/locate.database .
134 .Bd -literal
135 $ locate -d db1 -d db2 -d db3 pattern
136 .Ed
137 .Pp
138 is the same as
139 .Bd -literal
140 $ locate -d db1:db2:db3 pattern
141 .Ed
142 .Pp
143 or
144 .Bd -literal
145 .Dq $ locate -d db1:db2 -d db3 pattern .
146 .Ed
147 .Pp
148 If
149 .Ar -
150 is given as the database name, standard input will be read instead.
151 For example, you can compress your database
152 and use:
153 .Bd -literal
154 $ zcat database.gz | locate -d - pattern
155 .Ed
156 .Pp
157 This might be useful on machines with a fast CPU and little RAM and slow
158 I/O. Note: you can only use
159 .Ar one
160 pattern for stdin.
161 .It Fl i
162 Ignore case distinctions in both the pattern and the database.
163 .It Fl l Ar number
164 Limit output to
165 .Ar number
166 of file names and exit.
167 .It Fl m
168 Use
169 .Xr mmap 2
170 instead of the
171 .Xr stdio 3
172 library.
173 This is the default behavior
174 and is faster in most cases.
175 .It Fl s
176 Use the
177 .Xr stdio 3
178 library instead of
179 .Xr mmap 2 .
180 .El
181 .Sh FILES
182 .Bl -tag -width /etc/periodic/weekly/310.locate -compact
183 .It Pa /var/db/locate.database
184 locate database
185 .It Pa /usr/libexec/locate.updatedb
186 Script to update the locate database
187 .It Pa /etc/periodic/weekly/310.locate
188 Script that starts the database rebuild
189 .El
190 .Sh ENVIRONMENT
191 .Bl -tag -width LOCATE_PATH -compact
192 .It Pa LOCATE_PATH
193 path to the locate database if set and not empty, ignored if the
194 .Fl d
195 option was specified.
196 .El
197 .Sh SEE ALSO
198 .Xr find 1 ,
199 .Xr whereis 1 ,
200 .Xr which 1 ,
201 .Xr fnmatch 3 ,
202 .Xr locate.updatedb 8
203 .Rs
204 .%A Woods, James A.
205 .%D 1983
206 .%T "Finding Files Fast"
207 .%J ";login"
208 .%V 8:1
209 .%P pp. 8-10
210 .Re
211 .Sh BUGS
212 The
213 .Nm
214 program may fail to list some files that are present, or may
215 list files that have been removed from the system.  This is because
216 locate only reports files that are present in the database, which is
217 typically only regenerated once a week by the
218 .Pa /etc/periodic/weekly/310.locate
219 script.  Use
220 .Xr find 1
221 to locate files that are of a more transitory nature.
222 .Pp
223 The
224 .Nm
225 database was built by user
226 .Dq nobody .
227 .Xr find 1
228 skips directories,
229 which are not readable for user
230 .Dq nobody ,
231 group
232 .Dq nobody ,
233 or
234 world.
235 E.g. if your HOME directory is not world-readable, all your
236 files are
237 .Ar not
238 in the database.
239 .Pp
240 The
241 .Nm
242 database is not byte order independent.
243 It is not possible
244 to share the databases between machines with different byte order.
245 The current
246 .Nm
247 implementation understand databases in host byte order or
248 network byte order if both architectures use the same integer size.
249 So you can read on a
250 .Fx Ns /i386
251 machine
252 (little endian)
253 a locate database which was built on SunOS/sparc machine
254 (big endian, net).
255 .Sh HISTORY
256 The
257 .Nm
258 command first appeared in
259 .Bx 4.4 .
260 Many new features were
261 added in
262 .Fx 2.2 .