OSDN Git Service

GNU_findutils: update find and xargs manpages to 4.6.0
[linuxjm/jm.git] / manual / GNU_findutils / original / man1 / xargs.1
1 .TH XARGS 1 \" -*- nroff -*-
2 .SH NAME
3 xargs \- build and execute command lines from standard input
4 .SH SYNOPSIS
5 .B xargs
6 .nh
7 [\fB\-0prtx\fR]
8 [\fB\-E \fIeof-str\fR]
9 [\fB\-e\fR[\fIeof-str\fR]]
10 [\fB\-\-eof\fR[=\fIeof-str\fR]]
11 [\fB\-\-null\fR]
12 [\fB\-d \fIdelimiter\fR]
13 [\fB\-\-delimiter \fIdelimiter\fR]
14 [\fB\-I \fIreplace-str\fR]
15 [\fB\-i\fR[\fIreplace-str\fR]]
16 [\fB\-\-replace\fR[=\fIreplace-str\fR]]
17 [\fB\-l\fR[\fImax-lines\fR]]
18 [\fB\-L \fImax-lines\fR]
19 [\fB\-\-max\-lines\fR[=\fImax-lines\fR]]
20 [\fB\-n \fImax-args\fR]
21 [\fB\-\-max\-args\fR=\fImax-args\fR]
22 [\fB\-s \fImax-chars\fR]
23 [\fB\-\-max\-chars\fR=\fImax-chars\fR]
24 [\fB\-P \fImax-procs\fR]
25 [\fB\-\-max\-procs\fR=\fImax-procs\fR]
26 [\fB\-\-process\-slot\-var\fR=\fIname\fR]
27 [\fB\-\-interactive\fR]
28 [\fB\-\-verbose\fR]
29 [\fB\-\-exit\fR]
30 [\fB\-\-no\-run\-if\-empty\fR]
31 [\fB\-\-arg\-file\fR=\fIfile\fR]
32 [\fB\-\-show\-limits\fR]
33 [\fB\-\-version\fR]
34 [\fB\-\-help\fR]
35 [\fIcommand\fR [\fIinitial-arguments\fR]]
36 .hy
37 .SH DESCRIPTION
38 This manual page
39 documents the GNU version of
40 .BR xargs .
41 .B xargs
42 reads items from the standard input, delimited by blanks (which can be
43 protected with double or single quotes or a backslash) or newlines,
44 and executes the
45 .I command
46 (default is
47 .IR /bin/echo )
48 one or more times with any
49 .I initial-arguments
50 followed by items read from standard input.  Blank lines on the
51 standard input are ignored.
52 .P
53 The command line for
54 .I command
55 is built up until it reaches a system-defined limit (unless the
56 .B \-n
57 and
58 .B \-L
59 options are used).  The specified
60 .I command
61 will be invoked as many times as necessary to use up the list of input
62 items.  In general, there will be many fewer invocations of
63 .I command
64 than there were items in the input.  This will normally have
65 significant performance benefits.  Some commands can usefully be
66 executed in parallel too; see the
67 .B \-P
68 option.
69 .P
70 Because Unix filenames can contain blanks and newlines, this default
71 behaviour is often problematic; filenames containing blanks
72 and/or newlines are incorrectly processed by
73 .BR xargs .
74 In these situations it is better to use the
75 .B \-0
76 option, which
77 prevents such problems.   When using this option you will need to
78 ensure that the program which produces the input for
79 .B xargs
80 also uses a null character as a separator.  If that program is
81 GNU
82 .B find
83 for example, the
84 .B \-print0
85 option does this for you.
86 .P
87 If any invocation of the command exits with a status of 255,
88 .B xargs
89 will stop immediately without reading any further input.  An error
90 message is issued on stderr when this happens.
91 .SH OPTIONS
92 .TP
93 .PD
94 .B \-0, \-\-null
95 Input items are terminated by a null character instead of by
96 whitespace, and the quotes and backslash are not special (every
97 character is taken literally).  Disables the end of file string, which
98 is treated like any other argument.  Useful when input items might
99 contain white space, quote marks, or backslashes.  The GNU find
100 \-print0 option produces input suitable for this mode.
101
102 .TP
103 .PD
104 .BI "\-a " file ", \-\-arg\-file=" file
105 Read items from
106 .I file
107 instead of standard input.  If you use this option, stdin remains
108 unchanged when commands are run.  Otherwise, stdin is redirected
109 from
110 .IR /dev/null .
111
112 .TP
113 .PD
114 .BI "\-\-delimiter=" delim ", \-d" " delim"
115 Input items are terminated by the specified character.  The specified
116 delimiter may be a single character, a C-style character escape such
117 as
118 .BR \en ,
119 or an octal or hexadecimal escape code.  Octal and hexadecimal
120 escape codes are understood as for the
121 .B printf
122 command.   Multibyte characters are not supported.
123 When processing the input, quotes and backslash are not special; every
124 character in the input is taken literally.  The
125 .B \-d
126 option disables any end-of-file string, which is treated like any
127 other argument.  You can use this option when the input consists of
128 simply newline-separated items, although it is almost always better to
129 design your program to use
130 .B \-\-null
131 where this is possible.
132
133 .TP
134 .BI \-E " eof-str"
135 Set the end of file string to \fIeof-str\fR.  If the end of file
136 string occurs as a line of input, the rest of the input is ignored.
137 If neither
138 .B \-E
139 nor
140 .B \-e
141 is used, no end of file string is used.
142 .TP
143 .PD
144 .BR \-e "[\fIeof-str\fR], " "\-\-eof" [\fI=eof-str\fR]
145 This option is a synonym for the
146 .B \-E
147 option.  Use
148 .B \-E
149 instead,
150 because it is POSIX compliant while this option is not.  If
151 \fIeof-str\fR is omitted, there is no end of file string.  If neither
152 .B \-E
153 nor
154 .B \-e
155 is used, no end of file string is used.
156 .TP
157 .BI \-I " replace-str"
158 Replace occurrences of \fIreplace-str\fR in the initial-arguments with
159 names read from standard input.  Also, unquoted blanks do not
160 terminate input items; instead the separator is the newline character.
161 Implies
162 .B \-x
163 and
164 .B \-L
165 1.
166 .TP
167 .PD
168 .BR \-i "[\fIreplace-str\fR], " "\-\-replace" [\fI=replace-str\fR]
169 This option is a synonym for
170 .BI \-I replace-str
171 if
172 .I replace-str
173 is specified.  If the
174 .I replace-str
175 argument is missing, the effect is the same as
176 .BR \-I {}.
177 This option is deprecated; use
178 .B \-I
179 instead.
180 .TP
181 .BI \-L " max-lines"
182 Use at most \fImax-lines\fR nonblank input lines per command line.
183 Trailing blanks cause an input line to be logically continued on the
184 next input line.  Implies
185 .BR \-x .
186 .TP
187 .PD
188 .BR \-l "[\fImax-lines\fR], " \-\-max-lines "[=\fImax-lines\fR]"
189 Synonym for the
190 .B \-L
191 option.  Unlike
192 .BR \-L ,
193 the
194 .I max-lines
195 argument is optional.  If
196 .I max-lines
197 is not specified, it defaults to one.  The
198 .B \-l
199 option is deprecated since the POSIX standard specifies
200 .B \-L
201 instead.
202 .TP
203 .PD
204 .BI \-n " max-args\fB, \fI" "\-\-max\-args" \fR=\fImax-args
205 Use at most \fImax-args\fR arguments per command line.  Fewer than
206 .I max-args
207 arguments will be used if the size (see the
208 .B \-s
209 option) is exceeded, unless the
210 .B \-x
211 option is given, in which case
212 .B xargs will exit.
213 .TP
214 .PD
215 .BI \-P " max-procs\fR, \fI" \-\-max\-procs "\fR=\fImax-procs"
216 Run up to
217 .I max-procs
218 processes at a time; the default is 1.  If
219 .I max-procs
220 is 0,
221 .B xargs
222 will run as many processes as
223 possible at a time.  Use the
224 .B \-n
225 option or the
226 .B \-L
227 option with
228 .BR \-P ;
229 otherwise chances are that only one exec will be done.
230 While
231 .B xargs
232 is running, you can send its process a SIGUSR1 signal to increase the
233 number of commands to run simultaneously, or a SIGUSR2 to decrease the
234 number.  You cannot increase it above an implementation-defined limit
235 (which is shown with \-\-show-limits).  You cannot decrease it below
236 1.
237 .B xargs
238 never terminates its commands; when asked to decrease, it merely
239 waits for more than one existing command to terminate before starting
240 another.
241
242 .B Please note
243 that it is up to the called processes to properly manage parallel
244 access to shared resources.  For example, if more than one of them
245 tries to print to stdout, the ouptut will be produced in an
246 indeterminate order (and very likely mixed up) unless the processes
247 collaborate in some way to prevent this.  Using some kind of locking
248 scheme is one way to prevent such problems.  In general, using a
249 locking scheme will help ensure correct output but reduce performance.
250 If you don't want to tolerate the performance difference, simply
251 arrange for each process to produce a separate output file (or
252 otherwise use separate resources).
253 .TP
254 .PD
255 .B \-p, \-\-interactive
256 Prompt the user about whether to run each command line and read a line
257 from the terminal.  Only run the command line if the response starts
258 with `y' or `Y'.  Implies
259 .BR -t .
260 .TP
261 .PD
262 .BR \-\-process\-slot\-var "=\fIname\fR"
263 Set the environment variable
264 .I name
265 to a unique value in each running child process.  Values are reused
266 once child processes exit.  This can be used in a rudimentary load
267 distribution scheme, for example.
268 .TP
269 .PD
270 .B \-r, \-\-no\-run\-if\-empty
271 If the standard input does not contain any nonblanks, do not run the
272 command.  Normally, the command is run once even if there is no input.
273 This option is a GNU extension.
274 .TP
275 .PD
276 .BI -s " max-chars\fR, \fI" \-\-max\-chars "=\fImax-chars\fR"
277 Use at most \fImax-chars\fR characters per command line, including the
278 command and initial-arguments and the terminating nulls at the ends of
279 the argument strings.  The largest allowed value is system-dependent,
280 and is calculated as the argument length limit for exec, less the size
281 of your environment, less 2048 bytes of headroom.  If this value is
282 more than 128KiB, 128Kib is used as the default value; otherwise, the
283 default value is the maximum.  1KiB is 1024 bytes.
284 .B xargs
285 automatically adapts to tighter constraints.
286 .TP
287 .B "\-\-show\\-limits"
288 Display the limits on the command-line length which are imposed by the
289 operating system,
290 .BR xargs '
291 choice of buffer size and the
292 .B \-s
293 option.  Pipe the input from
294 .I /dev/null
295 (and perhaps specify
296 .BR --no-run-if-empty )
297 if you don't want
298 .B xargs
299 to do anything.
300 .TP
301 .B \-t, \-\-verbose
302 Print the command line on the standard error output before executing
303 it.
304 .TP
305 .PD
306 .B \-x, \-\-exit
307 Exit if the size (see the
308 .B \-s
309 option) is exceeded.
310 .TP
311 .B "\-\-help"
312 Print a summary of the options to
313 .B xargs
314 and exit.
315 .TP
316 .B "\-\-version"
317 Print the version number of
318 .B xargs
319 and exit.
320 .SH "EXAMPLES"
321 .nf
322 .B find /tmp \-name core \-type f \-print | xargs /bin/rm \-f
323
324 .fi
325 Find files named
326 .B core
327 in or below the directory
328 .B /tmp
329 and delete them.  Note that this will work incorrectly if there are
330 any filenames containing newlines or spaces.
331 .P
332 .B find /tmp \-name core \-type f \-print0 | xargs \-0 /bin/rm \-f
333
334 .fi
335 Find files named
336 .B core
337 in or below the directory
338 .B /tmp
339 and delete them, processing filenames in such a way that file or
340 directory names containing spaces or newlines are correctly handled.
341
342 .P
343 .B find /tmp \-depth \-name core \-type f \-delete
344
345 .fi
346 Find files named
347 .B core
348 in or below the directory
349 .B /tmp
350 and delete them, but more efficiently than in the previous example
351 (because we avoid the need to use
352 .BR fork (2)
353 and
354 .BR exec (2)
355 to launch
356 .B rm
357 and we don't need the extra
358 .B xargs
359 process).
360
361 .P
362 .nf
363 .B cut \-d: \-f1 < /etc/passwd | sort | xargs echo
364
365 .fi
366 Generates a compact listing of all the users on the system.
367
368 .P
369 .nf
370 .B xargs sh -c 'emacs \(dq$@\(dq < /dev/tty' emacs
371
372 .fi
373 Launches the minimum number of copies of Emacs needed, one after the
374 other, to edit the files listed on
375 .BR xargs '
376 standard input.  This example achieves the same effect as BSD's
377 .B -o
378 option, but in a more flexible and portable way.
379
380
381
382 .SH "EXIT STATUS"
383 .B xargs
384 exits with the following status:
385 .nf
386 0 if it succeeds
387 123 if any invocation of the command exited with status 1-125
388 124 if the command exited with status 255
389 125 if the command is killed by a signal
390 126 if the command cannot be run
391 127 if the command is not found
392 1 if some other error occurred.
393 .fi
394 .P
395 Exit codes greater than 128 are used by the shell to indicate that
396 a program died due to a fatal signal.
397 .SH "STANDARDS CONFORMANCE"
398 As of GNU xargs version 4.2.9, the default behaviour of
399 .B xargs
400 is not to have a logical end-of-file marker.  POSIX (IEEE Std 1003.1,
401 2004 Edition) allows this.
402 .P
403 The \-l and \-i options appear in the 1997 version of the POSIX
404 standard, but do not appear in the 2004 version of the standard.
405 Therefore you should use \-L and \-I instead, respectively.
406 .P
407 The POSIX standard allows implementations to have a limit on the size
408 of arguments to the
409 .B exec
410 functions.  This limit could be as low as 4096 bytes including the size of the
411 environment.  For scripts to be portable, they must not rely on a
412 larger value.  However, I know of no implementation whose actual limit
413 is that small.  The
414 .B \-\-show\-limits
415 option can be used to discover the actual limits in force on the
416 current system.
417
418
419 .SH "SEE ALSO"
420 \fBfind\fP(1), \fBlocate\fP(1), \fBlocatedb\fP(5), \fBupdatedb\fP(1),
421 \fBfork\fP(2), \fBexecvp\fP(3),
422 \fBkill\fP(1), \fBsignal\fP(7),
423
424 The  full documentation for
425 .B xargs
426 is maintained as a Texinfo manual.  If the
427 .B info
428 and
429 .B xargs
430 programs are properly installed at your site, the command
431 .B info xargs
432 should give you access to the complete manual.
433
434 .SH "BUGS"
435 The
436 .B \-L
437 option is incompatible with the
438 .B \-I
439 option, but perhaps should not be.
440 .P
441 It is not possible for
442 .B xargs
443 to be used securely, since there will always be a time gap between the
444 production of the list of input files and their use in the commands
445 that
446 .B xargs
447 issues.  If other users have access to the system, they can manipulate
448 the filesystem during this time window to force the action of the
449 commands
450 .B xargs
451 runs to apply to files that you didn't intend.  For a more detailed
452 discussion of this and related problems, please refer to the
453 ``Security Considerations'' chapter in the findutils Texinfo
454 documentation.  The
455 .B \-execdir
456 option of
457 .B find
458 can often be used as a more secure alternative.
459
460 When you use the
461 .B \-I
462 option, each line read from the input is buffered
463 internally.   This means that there is an upper limit on the length
464 of input line that
465 .B xargs
466 will accept when used with the
467 .B \-I
468 option.  To work around this
469 limitation, you can use the
470 .B \-s
471 option to increase the amount of
472 buffer space that
473 .B xargs
474 uses, and you can also use an extra invocation of
475 .B xargs
476 to ensure that very long lines do not occur.
477 For example:
478 .P
479 .B somecommand | xargs \-s 50000 echo | xargs \-I '{}' \-s 100000 rm '{}'
480 .P
481 Here, the first invocation of
482 .B xargs
483 has no input line length limit
484 because it doesn't use the
485 .B \-i
486 option.  The second invocation of
487 .B xargs
488 does have such a limit, but we have ensured that the it never encounters
489 a line which is longer than it can handle.   This is not an ideal
490 solution.  Instead, the
491 .B \-i
492 option should not impose a line length
493 limit, which is why this discussion appears in the BUGS section.
494 The problem doesn't occur with the output of
495 .BR find (1)
496 because it emits just one filename per line.
497 .P
498 The best way to report a bug is to use the form at
499 http://savannah.gnu.org/bugs/?group=findutils.
500 The reason for this is that you will then be able to track progress in
501 fixing the problem.   Other comments about \fBxargs\fP(1) and about
502 the findutils package in general can be sent to the
503 .I bug\-findutils
504 mailing list.  To join the list, send email to
505 .IR bug\-findutils\-request@gnu.org .