Print this page
3047 grep support for -r would be useful
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/man/man1/grep.1
+++ new/usr/src/man/man1/grep.1
1 1 '\" te
2 2 .\" Copyright 2012 Nexenta Systems, Inc. All rights reserved.
3 3 .\" Copyright 1989 AT&T
4 4 .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved
5 5 .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
6 6 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
7 7 .\" http://www.opengroup.org/bookstore/.
8 8 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
↓ open down ↓ |
8 lines elided |
↑ open up ↑ |
9 9 .\" This notice shall appear on any product containing this material.
10 10 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
11 11 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
12 12 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
13 13 .TH GREP 1 "Feb 26, 2008"
14 14 .SH NAME
15 15 grep \- search a file for a pattern
16 16 .SH SYNOPSIS
17 17 .LP
18 18 .nf
19 -\fB/usr/bin/grep\fR [\fB-c\fR | \fB-l\fR | \fB-q\fR] [\fB-bhinsvw\fR] \fIlimited-regular-expression\fR
20 - [\fIfilename\fR]...
19 +\fB/usr/bin/grep\fR [\fB-c\fR | \fB-l\fR |\fB-q\fR] [\fB-r\fR | \fB-R\fR] [\fB-bhinsvw\fR]
20 + \fIlimited-regular-expression\fR [\fIfilename\fR]...
21 21 .fi
22 22
23 23 .LP
24 24 .nf
25 -\fB/usr/xpg4/bin/grep\fR [\fB-E\fR | \fB-F\fR] [\fB-c\fR | \fB-l\fR | \fB-q\fR] [\fB-bhinsvwx\fR] \fB-e\fR \fIpattern_list\fR...
26 - [\fB-f\fR \fIpattern_file\fR]... [\fIfile\fR]...
25 +\fB/usr/xpg4/bin/grep\fR [\fB-E\fR | \fB-F\fR] [\fB-c\fR | \fB-l\fR | \fB-q\fR] [\fB-r\fR | \fB-R\fR]
26 + [\fB-bhinsvwx\fR] \fB-e\fR \fIpattern_list\fR... [\fB-f\fR \fIpattern_file\fR]...
27 + [\fIfile\fR]...
27 28 .fi
28 29
29 30 .LP
30 31 .nf
31 -\fB/usr/xpg4/bin/grep\fR [\fB-E\fR | \fB-F\fR] [\fB-c\fR | \fB-l\fR | \fB-q\fR] [\fB-bhinsvwx\fR]
32 - [\fB-e\fR \fIpattern_list\fR]... \fB-f\fR \fIpattern_file\fR... [\fIfile\fR]...
32 +\fB/usr/xpg4/bin/grep\fR [\fB-E\fR | \fB-F\fR] [\fB-c\fR | \fB-l\fR | \fB-q\fR] [\fB-r\fR | \fB-R\fR]
33 + [\fB-bhinsvwx\fR] [\fB-e\fR \fIpattern_list\fR]... \fB-f\fR \fIpattern_file\fR...
34 + [\fIfile\fR]...
33 35 .fi
34 36
35 37 .LP
36 38 .nf
37 -\fB/usr/xpg4/bin/grep\fR [\fB-E\fR | \fB-F\fR] [\fB-c\fR | \fB-l\fR | \fB-q\fR] [\fB-bhinsvwx\fR] \fIpattern\fR
38 - [\fIfile\fR]...
39 +\fB/usr/xpg4/bin/grep\fR [\fB-E\fR | \fB-F\fR] [\fB-c\fR | \fB-l\fR | \fB-q\fR] [\fB-r\fR | \fB-R\fR]
40 + [\fB-bhinsvwx\fR] \fIpattern\fR [\fIfile\fR]...
39 41 .fi
40 42
41 43 .SH DESCRIPTION
42 44 .sp
43 45 .LP
44 46 The \fBgrep\fR utility searches text files for a pattern and prints all lines
45 47 that contain that pattern. It uses a compact non-deterministic algorithm.
46 48 .sp
47 49 .LP
48 50 Be careful using the characters \fB$\fR, \fB*\fR, \fB[\fR, \fB^\fR, \fB|\fR,
49 51 \fB(\fR, \fB)\fR, and \fB\e\fR in the \fIpattern_list\fR because they are also
50 52 meaningful to the shell. It is safest to enclose the entire \fIpattern_list\fR
51 53 in single quotes \fBa\'\fR\&...\fBa\'\fR\&.
52 54 .sp
53 55 .LP
54 56 If no files are specified, \fBgrep\fR assumes standard input. Normally, each
55 57 line found is copied to standard output. The file name is printed before each
56 58 line found if there is more than one input file.
57 59 .SS "/usr/bin/grep"
58 60 .sp
59 61 .LP
60 62 The \fB/usr/bin/grep\fR utility uses limited regular expressions like those
61 63 described on the \fBregexp\fR(5) manual page to match the patterns.
62 64 .SS "/usr/xpg4/bin/grep"
63 65 .sp
64 66 .LP
65 67 The options \fB-E\fR and \fB-F\fR affect the way \fB/usr/xpg4/bin/grep\fR
66 68 interprets \fIpattern_list\fR. If \fB-E\fR is specified,
67 69 \fB/usr/xpg4/bin/grep\fR interprets \fIpattern_list\fR as a full regular
68 70 expression (see \fB-E\fR for description). If \fB-F\fR is specified,
69 71 \fBgrep\fR interprets \fIpattern_list\fR as a fixed string. If neither are
70 72 specified, \fBgrep\fR interprets \fIpattern_list\fR as a basic regular
71 73 expression as described on \fBregex\fR(5) manual page.
72 74 .SH OPTIONS
73 75 .sp
74 76 .LP
75 77 The following options are supported for both \fB/usr/bin/grep\fR and
76 78 \fB/usr/xpg4/bin/grep\fR:
77 79 .sp
78 80 .ne 2
79 81 .na
80 82 \fB\fB-b\fR\fR
81 83 .ad
82 84 .RS 6n
83 85 Precedes each line by the block number on which it was found. This can be
84 86 useful in locating block numbers by context (first block is 0).
85 87 .RE
86 88
87 89 .sp
88 90 .ne 2
89 91 .na
90 92 \fB\fB-c\fR\fR
91 93 .ad
92 94 .RS 6n
93 95 Prints only a count of the lines that contain the pattern.
94 96 .RE
95 97
96 98 .sp
97 99 .ne 2
98 100 .na
99 101 \fB\fB-h\fR\fR
100 102 .ad
101 103 .RS 6n
102 104 Prevents the name of the file containing the matching line from being prepended
103 105 to that line. Used when searching multiple files.
104 106 .RE
105 107
106 108 .sp
107 109 .ne 2
108 110 .na
109 111 \fB\fB-i\fR\fR
110 112 .ad
111 113 .RS 6n
112 114 Ignores upper/lower case distinction during comparisons.
113 115 .RE
114 116
115 117 .sp
116 118 .ne 2
117 119 .na
118 120 \fB\fB-l\fR\fR
119 121 .ad
120 122 .RS 6n
121 123 Prints only the names of files with matching lines, separated by NEWLINE
122 124 characters. Does not repeat the names of files when the pattern is found more
123 125 than once.
124 126 .RE
↓ open down ↓ |
76 lines elided |
↑ open up ↑ |
125 127
126 128 .sp
127 129 .ne 2
128 130 .na
129 131 \fB\fB-n\fR\fR
130 132 .ad
131 133 .RS 6n
132 134 Precedes each line by its line number in the file (first line is 1).
133 135 .RE
134 136
137 +.sp
138 +.ne 2
139 +.na
140 +\fB\fB-r\fR\fR
141 +.ad
142 +.RS 6n
143 +Read all files under each directory, recursively. Follow symbolic links on
144 +the command line, but skip symlinks that are encountered recursively. If file
145 +is a device, FIFO, or socket, skip it.
146 +.RE
147 +
148 +.sp
149 +.ne 2
150 +.na
151 +\fB\fB-R\fR\fR
152 +.ad
153 +.RS 6n
154 +Read all files under each directory, recursively, following all symbolic links.
155 +.RE
156 +
135 157 .sp
136 158 .ne 2
137 159 .na
138 160 \fB\fB-q\fR\fR
139 161 .ad
140 162 .RS 6n
141 163 Quiet. Does not write anything to the standard output, regardless of matching
142 164 lines. Exits with zero status if an input line is selected.
143 165 .RE
144 166
145 167 .sp
146 168 .ne 2
147 169 .na
148 170 \fB\fB-s\fR\fR
149 171 .ad
150 172 .RS 6n
151 173 Suppresses error messages about nonexistent or unreadable files.
152 174 .RE
153 175
154 176 .sp
155 177 .ne 2
156 178 .na
157 179 \fB\fB-v\fR\fR
158 180 .ad
159 181 .RS 6n
160 182 Prints all lines except those that contain the pattern.
161 183 .RE
162 184
163 185 .sp
164 186 .ne 2
165 187 .na
166 188 \fB\fB-w\fR\fR
167 189 .ad
168 190 .RS 6n
169 191 Searches for the expression as a word as if surrounded by \fB\e<\fR and
170 192 \fB\e>\fR\&.
171 193 .RE
172 194
173 195 .SS "/usr/xpg4/bin/grep"
174 196 .sp
175 197 .LP
176 198 The following options are supported for \fB/usr/xpg4/bin/grep\fR only:
177 199 .sp
178 200 .ne 2
179 201 .na
180 202 \fB\fB-e\fR \fIpattern_list\fR\fR
181 203 .ad
182 204 .RS 19n
183 205 Specifies one or more patterns to be used during the search for input. Patterns
184 206 in \fIpattern_list\fR must be separated by a NEWLINE character. A null pattern
185 207 can be specified by two adjacent newline characters in \fIpattern_list\fR.
186 208 Unless the \fB-E\fR or \fB-F\fR option is also specified, each pattern is
187 209 treated as a basic regular expression. Multiple \fB-e\fR and \fB-f\fR options
188 210 are accepted by \fBgrep\fR. All of the specified patterns are used when
189 211 matching lines, but the order of evaluation is unspecified.
190 212 .RE
191 213
192 214 .sp
193 215 .ne 2
194 216 .na
195 217 \fB\fB-E\fR\fR
196 218 .ad
197 219 .RS 19n
198 220 Matches using full regular expressions. Treats each pattern specified as a full
199 221 regular expression. If any entire full regular expression pattern matches an
200 222 input line, the line is matched. A null full regular expression matches every
201 223 line. Each pattern is interpreted as a full regular expression as described on
202 224 the \fBregex\fR(5) manual page, except for \fB\e(\fR and \fB\e)\fR, and
203 225 including:
204 226 .RS +4
205 227 .TP
206 228 1.
207 229 A full regular expression followed by \fB+\fR that matches one or more
208 230 occurrences of the full regular expression.
209 231 .RE
210 232 .RS +4
211 233 .TP
212 234 2.
213 235 A full regular expression followed by \fB?\fR that matches 0 or 1
214 236 occurrences of the full regular expression.
215 237 .RE
216 238 .RS +4
217 239 .TP
218 240 3.
219 241 Full regular expressions separated by | or by a new-line that match strings
220 242 that are matched by any of the expressions.
221 243 .RE
222 244 .RS +4
223 245 .TP
224 246 4.
225 247 A full regular expression that is enclosed in parentheses \fB()\fR for
226 248 grouping.
227 249 .RE
228 250 The order of precedence of operators is \fB[\|]\fR, then \fB*\|?\|+\fR, then
229 251 concatenation, then | and new-line.
230 252 .RE
231 253
232 254 .sp
233 255 .ne 2
234 256 .na
235 257 \fB\fB-f\fR \fIpattern_file\fR\fR
236 258 .ad
237 259 .RS 19n
238 260 Reads one or more patterns from the file named by the path name
239 261 \fIpattern_file\fR. Patterns in \fIpattern_file\fR are terminated by a NEWLINE
240 262 character. A null pattern can be specified by an empty line in
241 263 \fIpattern_file\fR. Unless the \fB-E\fR or \fB-F\fR option is also specified,
242 264 each pattern is treated as a basic regular expression.
243 265 .RE
244 266
245 267 .sp
246 268 .ne 2
247 269 .na
248 270 \fB\fB-F\fR\fR
249 271 .ad
250 272 .RS 19n
251 273 Matches using fixed strings. Treats each pattern specified as a string instead
252 274 of a regular expression. If an input line contains any of the patterns as a
253 275 contiguous sequence of bytes, the line is matched. A null string matches every
254 276 line. See \fBfgrep\fR(1) for more information.
255 277 .RE
256 278
257 279 .sp
258 280 .ne 2
259 281 .na
260 282 \fB\fB-x\fR\fR
261 283 .ad
262 284 .RS 19n
263 285 Considers only input lines that use all characters in the line to match an
264 286 entire fixed string or regular expression to be matching lines.
265 287 .RE
266 288
267 289 .SH OPERANDS
268 290 .sp
269 291 .LP
270 292 The following operands are supported:
271 293 .sp
272 294 .ne 2
273 295 .na
274 296 \fB\fIfile\fR\fR
275 297 .ad
276 298 .RS 8n
277 299 A path name of a file to be searched for the patterns. If no \fIfile\fR
278 300 operands are specified, the standard input is used.
279 301 .RE
280 302
281 303 .SS "/usr/bin/grep"
282 304 .sp
283 305 .ne 2
284 306 .na
285 307 \fB\fIpattern\fR\fR
286 308 .ad
287 309 .RS 11n
288 310 Specifies a pattern to be used during the search for input.
289 311 .RE
290 312
291 313 .SS "/usr/xpg4/bin/grep"
292 314 .sp
293 315 .ne 2
294 316 .na
295 317 \fB\fIpattern\fR\fR
296 318 .ad
297 319 .RS 11n
298 320 Specifies one or more patterns to be used during the search for input. This
299 321 operand is treated as if it were specified as \fB-e\fR \fIpattern_list\fR.
300 322 .RE
301 323
302 324 .SH USAGE
303 325 .sp
304 326 .LP
305 327 The \fB-e\fR \fIpattern_list\fR option has the same effect as the
306 328 \fIpattern_list\fR operand, but is useful when \fIpattern_list\fR begins with
307 329 the hyphen delimiter. It is also useful when it is more convenient to provide
308 330 multiple patterns as separate arguments.
309 331 .sp
310 332 .LP
311 333 Multiple \fB-e\fR and \fB-f\fR options are accepted and \fBgrep\fR uses all of
312 334 the patterns it is given while matching input text lines. Notice that the order
313 335 of evaluation is not specified. If an implementation finds a null string as a
314 336 pattern, it is allowed to use that pattern first, matching every line, and
315 337 effectively ignore any other patterns.
316 338 .sp
317 339 .LP
318 340 The \fB-q\fR option provides a means of easily determining whether or not a
319 341 pattern (or string) exists in a group of files. When searching several files,
320 342 it provides a performance improvement (because it can quit as soon as it finds
321 343 the first match) and requires less care by the user in choosing the set of
322 344 files to supply as arguments (because it exits zero if it finds a match even if
323 345 \fBgrep\fR detected an access or read error on earlier file operands).
324 346 .SS "Large File Behavior"
325 347 .sp
326 348 .LP
327 349 See \fBlargefile\fR(5) for the description of the behavior of \fBgrep\fR when
328 350 encountering files greater than or equal to 2 Gbyte ( 2^31 bytes).
329 351 .SH EXAMPLES
330 352 .LP
331 353 \fBExample 1 \fRFinding All Uses of a Word
332 354 .sp
333 355 .LP
334 356 To find all uses of the word "\fBPosix\fR" (in any case) in the file
335 357 \fBtext.mm\fR, and write with line numbers:
336 358
337 359 .sp
338 360 .in +2
339 361 .nf
340 362 example% \fB/usr/bin/grep -i -n posix text.mm\fR
341 363 .fi
342 364 .in -2
343 365 .sp
344 366
345 367 .LP
346 368 \fBExample 2 \fRFinding All Empty Lines
347 369 .sp
348 370 .LP
349 371 To find all empty lines in the standard input:
350 372
351 373 .sp
352 374 .in +2
353 375 .nf
354 376 example% \fB/usr/bin/grep ^$\fR
355 377 .fi
356 378 .in -2
357 379 .sp
358 380
359 381 .sp
360 382 .LP
361 383 or
362 384
363 385 .sp
364 386 .in +2
365 387 .nf
366 388 example% \fB/usr/bin/grep -v .\fR
367 389 .fi
368 390 .in -2
369 391 .sp
370 392
371 393 .LP
372 394 \fBExample 3 \fRFinding Lines Containing Strings
373 395 .sp
374 396 .LP
375 397 All of the following commands print all lines containing strings \fBabc\fR or
376 398 \fBdef\fR or both:
377 399
378 400 .sp
379 401 .in +2
380 402 .nf
381 403 example% \fB/usr/xpg4/bin/grep 'abc
382 404 def'\fR
383 405 example% \fB/usr/xpg4/bin/grep -e 'abc
384 406 def'\fR
385 407 example% \fB/usr/xpg4/bin/grep -e 'abc' -e 'def'\fR
386 408 example% \fB/usr/xpg4/bin/grep -E 'abc|def'\fR
387 409 example% \fB/usr/xpg4/bin/grep -E -e 'abc|def'\fR
388 410 example% \fB/usr/xpg4/bin/grep -E -e 'abc' -e 'def'\fR
389 411 example% \fB/usr/xpg4/bin/grep -E 'abc
390 412 def'\fR
391 413 example% \fB/usr/xpg4/bin/grep -E -e 'abc
392 414 def'\fR
393 415 example% \fB/usr/xpg4/bin/grep -F -e 'abc' -e 'def'\fR
394 416 example% \fB/usr/xpg4/bin/grep -F 'abc
395 417 def'\fR
396 418 example% \fB/usr/xpg4/bin/grep -F -e 'abc
397 419 def'\fR
398 420 .fi
399 421 .in -2
400 422 .sp
401 423
402 424 .LP
403 425 \fBExample 4 \fRFinding Lines with Matching Strings
404 426 .sp
405 427 .LP
406 428 Both of the following commands print all lines matching exactly \fBabc\fR or
407 429 \fBdef\fR:
408 430
409 431 .sp
410 432 .in +2
411 433 .nf
412 434 example% \fB/usr/xpg4/bin/grep -E '^abc$ ^def$'\fR
413 435 example% \fB/usr/xpg4/bin/grep -F -x 'abc def'\fR
414 436 .fi
415 437 .in -2
416 438 .sp
417 439
418 440 .SH ENVIRONMENT VARIABLES
419 441 .sp
420 442 .LP
421 443 See \fBenviron\fR(5) for descriptions of the following environment variables
422 444 that affect the execution of \fBgrep\fR: \fBLANG\fR, \fBLC_ALL\fR,
423 445 \fBLC_COLLATE\fR, \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and \fBNLSPATH\fR.
424 446 .SH EXIT STATUS
425 447 .sp
426 448 .LP
427 449 The following exit values are returned:
428 450 .sp
429 451 .ne 2
430 452 .na
431 453 \fB\fB0\fR\fR
432 454 .ad
433 455 .RS 5n
434 456 One or more matches were found.
435 457 .RE
436 458
437 459 .sp
438 460 .ne 2
439 461 .na
440 462 \fB\fB1\fR\fR
441 463 .ad
442 464 .RS 5n
443 465 No matches were found.
444 466 .RE
445 467
446 468 .sp
447 469 .ne 2
448 470 .na
449 471 \fB\fB2\fR\fR
450 472 .ad
451 473 .RS 5n
452 474 Syntax errors or inaccessible files (even if matches were found).
453 475 .RE
454 476
455 477 .SH ATTRIBUTES
456 478 .sp
457 479 .LP
458 480 See \fBattributes\fR(5) for descriptions of the following attributes:
459 481 .SS "/usr/bin/grep"
460 482 .sp
461 483
462 484 .sp
463 485 .TS
464 486 box;
465 487 c | c
466 488 l | l .
467 489 ATTRIBUTE TYPE ATTRIBUTE VALUE
468 490 _
469 491 CSI Not Enabled
470 492 .TE
471 493
472 494 .SS "/usr/xpg4/bin/grep"
473 495 .sp
474 496
475 497 .sp
476 498 .TS
477 499 box;
478 500 c | c
479 501 l | l .
480 502 ATTRIBUTE TYPE ATTRIBUTE VALUE
481 503 _
482 504 CSI Enabled
483 505 _
484 506 Interface Stability Committed
485 507 _
486 508 Standard See \fBstandards\fR(5).
487 509 .TE
488 510
489 511 .SH SEE ALSO
490 512 .sp
491 513 .LP
492 514 \fBegrep\fR(1), \fBfgrep\fR(1), \fBsed\fR(1), \fBsh\fR(1), \fBattributes\fR(5),
493 515 \fBenviron\fR(5), \fBlargefile\fR(5), \fBregex\fR(5), \fBregexp\fR(5),
494 516 \fBstandards\fR(5)
495 517 .SH NOTES
496 518 .SS "/usr/bin/grep"
497 519 .sp
498 520 .LP
499 521 Lines are limited only by the size of the available virtual memory. If there is
500 522 a line with embedded nulls, \fBgrep\fR only matches up to the first null. If
501 523 the line matches, the entire line is printed.
502 524 .SS "/usr/xpg4/bin/grep"
503 525 .sp
504 526 .LP
505 527 The results are unspecified if input files contain lines longer than
506 528 \fBLINE_MAX\fR bytes or contain binary data. \fBLINE_MAX\fR is defined in
507 529 \fB/usr/include/limits.h\fR.
↓ open down ↓ |
363 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX