Print this page
4703 would like xargs support for -P
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/man/man1/xargs.1
+++ new/usr/src/man/man1/xargs.1
1 1 '\" te
2 2 .\" Copyright 1989 AT&T Copyright (c) 1992, X/Open Company Limited All Rights Reserved Portions Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved
3 3 .\" 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
4 4 .\" http://www.opengroup.org/bookstore/.
5 5 .\" 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.
6 6 .\" This notice shall appear on any product containing this material.
7 7 .\" 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.
8 8 .\" 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.
9 9 .\" 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]
10 -.TH XARGS 1 "November 24, 2012"
10 +.TH XARGS 1 "March 31, 2014"
11 11 .SH NAME
12 12 xargs \- construct argument lists and invoke utility
13 13 .SH SYNOPSIS
14 14 .LP
15 15 .nf
16 16 \fBxargs\fR [\fB-t\fR] [\fB-0\fR] [\fB-p\fR] [\fB-e\fR[\fIeofstr\fR]] [\fB-E\fR \fIeofstr\fR]
17 17 [\fB-I\fR \fIreplstr\fR] [\fB-i\fR[\fIreplstr\fR]] [\fB-L\fR \fInumber\fR] [\fB-l\fR[\fInumber\fR]]
18 - [\fB-n\fR \fInumber\fR [\fB-x\fR]] [\fB-s\fR \fIsize\fR] [\fIutility\fR [\fIargument\fR...]]
18 + [\fB-n\fR \fInumber\fR [\fB-x\fR]] [\fB-P\fR \fImaxprocs\fR] [\fB-s\fR \fIsize\fR]
19 + [\fIutility\fR [\fIargument\fR...]]
19 20 .fi
20 21
21 22 .SH DESCRIPTION
22 23 .sp
23 24 .LP
24 25 The \fBxargs\fR utility constructs a command line consisting of the
25 26 \fIutility\fR and \fIargument\fR operands specified followed by as many
26 27 arguments read in sequence from standard input as fit in length and number
27 28 constraints specified by the options. The \fBxargs\fR utility then invokes the
28 29 constructed command line and waits for its completion. This sequence is
29 30 repeated until an end-of-file condition is detected on standard input or an
30 31 invocation of a constructed command line returns an exit status of \fB255\fR.
31 32 .sp
32 33 .LP
33 34 Arguments in the standard input must be separated by unquoted blank characters,
34 35 or unescaped blank characters or newline characters. A string of zero or more
35 36 non-double-quote (\fB"\fR) and non-newline characters can be quoted by
36 37 enclosing them in double-quotes. A string of zero or more non-apostrophe
37 38 (\fB\&'\fR) and non-newline characters can be quoted by enclosing them in
38 39 apostrophes. Any unquoted character can be escaped by preceding it with a
39 40 backslash (\fB\e\fR). The \fIutility\fR are executed one or more times until
40 41 the end-of-file is reached. The results are unspecified if the utility named by
41 42 \fIutility\fR attempts to read from its standard input.
42 43 .sp
43 44 .LP
44 45 The generated command line length is the sum of the size in bytes of the
45 46 utility name and each argument treated as strings, including a null byte
46 47 terminator for each of these strings. The \fBxargs\fR utility limits the
47 48 command line length such that when the command line is invoked, the combined
48 49 argument and environment lists can not exceed \fB{ARG_MAX}\(mi2048\fR bytes.
49 50 Within this constraint, if neither the \fB-n\fR nor the \fB-s\fR option is
50 51 specified, the default command line length is at least \fB{LINE_MAX}\fR.
51 52 .SH OPTIONS
52 53 .sp
53 54 .LP
54 55 The following options are supported:
55 56 .sp
56 57 .ne 2
57 58 .na
58 59 \fB\fB\fR\fB-e\fR\fB[\fR\fIeofstr\fR\fB]\fR\fR
59 60 .ad
60 61 .RS 15n
61 62 Uses \fIeofstr\fR as the logical end-of-file string. Underscore (\fB_\fR) is
62 63 assumed for the logical \fBEOF\fR string if neither \fB-e\fR nor \fB-E\fR is
63 64 used. When the \fIeofstr\fR option-argument is omitted, the logical \fBEOF\fR
64 65 string capability is disabled and underscores are taken literally. The
65 66 \fBxargs\fR utility reads standard input until either end-of-file or the
66 67 logical \fBEOF\fR string is encountered.
67 68 .RE
68 69
69 70 .sp
70 71 .ne 2
71 72 .na
72 73 \fB\fB-E\fR \fIeofstr\fR\fR
73 74 .ad
74 75 .RS 15n
75 76 Specifies a logical end-of-file string to replace the default underscore.
76 77 \fBxargs\fR reads standard input until either end-of-file or the logical EOF
77 78 string is encountered. When \fIeofstr\fR is a null string, the logical
78 79 end-of-file string capability is disabled and underscore characters are taken
79 80 literally.
80 81 .RE
81 82
82 83 .sp
83 84 .ne 2
84 85 .na
85 86 \fB\fB-I\fR \fIreplstr\fR\fR
86 87 .ad
87 88 .RS 15n
88 89 Insert mode. \fIutility\fR is executed for each line from standard input,
89 90 taking the entire line as a single argument, inserting it in \fIargument\fR
90 91 \fIs\fR for each occurrence of \fIreplstr\fR. A maximum of five arguments in
91 92 \fIargument\fRs can each contain one or more instances of \fIreplstr\fR. Any
92 93 blank characters at the beginning of each line are ignored. Constructed
93 94 arguments cannot grow larger than 255 bytes. Option \fB-x\fR is forced on. The
94 95 \fB-I\fR and \fB-i\fR options are mutually exclusive; the last one specified
95 96 takes effect.
96 97 .RE
97 98
98 99 .sp
99 100 .ne 2
100 101 .na
101 102 \fB\fB\fR\fB-i\fR\fB[\fR\fIreplstr\fR\fB]\fR\fR
102 103 .ad
103 104 .RS 15n
104 105 This option is equivalent to \fB-I\fR \fIreplstr\fR. The string \fB{\|}\fR is
105 106 assumed for \fIreplstr\fR if the option-argument is omitted.
106 107 .RE
107 108
108 109 .sp
109 110 .ne 2
110 111 .na
111 112 \fB\fB-L\fR \fInumber\fR\fR
112 113 .ad
113 114 .RS 15n
114 115 The \fIutility\fR is executed for each non-empty \fInumber\fR lines of
115 116 arguments from standard input. The last invocation of \fIutility\fR is with
116 117 fewer lines of arguments if fewer than \fInumber\fR remain. A line is
117 118 considered to end with the first newline character unless the last character of
118 119 the line is a blank character; a trailing blank character signals continuation
119 120 to the next non-empty line, inclusive. The \fB-L\fR, \fB-l\fR, and \fB-n\fR
120 121 options are mutually exclusive; the last one specified takes effect.
121 122 .RE
122 123
123 124 .sp
124 125 .ne 2
125 126 .na
126 127 \fB\fB-l[\fR\fInumber\fR\fB]\fR\fR
127 128 .ad
128 129 .RS 15n
129 130 (The letter ell.) This option is equivalent to \fB-L\fR \fInumber\fR. If
130 131 \fInumber\fR is omitted, \fB1\fR is assumed. Option \fB-x\fR is forced on.
131 132 .RE
132 133
133 134 .sp
134 135 .ne 2
135 136 .na
136 137 \fB\fB-n\fR \fInumber\fR\fR
137 138 .ad
138 139 .RS 15n
139 140 Invokes \fIutility\fR using as many standard input arguments as possible, up to
140 141 \fInumber\fR (a positive decimal integer) arguments maximum. Fewer arguments
141 142 are used if:
142 143 .RS +4
143 144 .TP
144 145 .ie t \(bu
145 146 .el o
146 147 The command line length accumulated exceeds the size specified by the \fB-s\fR
147 148 option (or \fB{LINE_MAX}\fR if there is no \fB-s\fR option), or
148 149 .RE
149 150 .RS +4
150 151 .TP
151 152 .ie t \(bu
152 153 .el o
153 154 The last iteration has fewer than \fInumber\fR, but not zero, operands
154 155 remaining.
155 156 .RE
156 157 .RE
157 158
158 159 .sp
↓ open down ↓ |
130 lines elided |
↑ open up ↑ |
159 160 .ne 2
160 161 .na
161 162 \fB-p\fR
162 163 .ad
163 164 .RS 15n
164 165 Prompt mode. The user is asked whether to execute \fIutility\fR at each
165 166 invocation. Trace mode (\fB-t\fR) is turned on to write the command instance to
166 167 be executed, followed by a prompt to standard error. An affirmative response
167 168 (specific to the user's locale) read from \fB/dev/tty\fR executes the command;
168 169 otherwise, that particular invocation of \fIutility\fR is skipped.
170 +.RE
171 +
172 +.sp
173 +.ne 2
174 +.na
175 +\fB\fB-P\fR \fImaxprocs\fR\fR
176 +.ad
177 +.RS 15n
178 +Invokes \fIutility\fR using at most \fImaxprocs\fR (a positive decimal integer)
179 +parallel child processes.
169 180 .RE
170 181
171 182 .sp
172 183 .ne 2
173 184 .na
174 185 \fB\fB-s\fR \fIsize\fR\fR
175 186 .ad
176 187 .RS 15n
177 188 Invokes \fIutility\fR using as many standard input arguments as possible
178 189 yielding a command line length less than \fIsize\fR (a positive decimal
179 190 integer) bytes. Fewer arguments are used if:
180 191 .RS +4
181 192 .TP
182 193 .ie t \(bu
183 194 .el o
184 195 The total number of arguments exceeds that specified by the \fB-n\fR option, or
185 196 .RE
186 197 .RS +4
187 198 .TP
188 199 .ie t \(bu
189 200 .el o
190 201 The total number of lines exceeds that specified by the \fB-L\fR option, or
191 202 .RE
192 203 .RS +4
193 204 .TP
194 205 .ie t \(bu
195 206 .el o
196 207 End of file is encountered on standard input before \fIsize\fR bytes are
197 208 accumulated.
198 209 .RE
199 210 Values of \fIsize\fR up to at least \fB{LINE_MAX}\fR bytes are supported,
200 211 provided that the constraints specified in DESCRIPTION are met. It is not
201 212 considered an error if a value larger than that supported by the implementation
202 213 or exceeding the constraints specified in DESCRIPTION is specified. \fBxargs\fR
203 214 uses the largest value it supports within the constraints.
204 215 .RE
205 216
206 217 .sp
207 218 .ne 2
208 219 .na
209 220 \fB\fB-t\fR\fR
210 221 .ad
211 222 .RS 6n
212 223 Enables trace mode. Each generated command line is written to standard error
213 224 just prior to invocation.
214 225 .RE
215 226
216 227 .sp
217 228 .ne 2
218 229 .na
219 230 \fB\fB-x\fR\fR
220 231 .ad
221 232 .RS 6n
222 233 Terminates if a command line containing \fInumber\fR arguments (see the
223 234 \fB-n\fR option above) or \fInumber\fR lines (see the \fB-L\fR option above)
224 235 does not fit in the implied or specified size (see the \fB-s\fR option above).
225 236 .RE
226 237
227 238 .sp
228 239 .ne 2
229 240 .na
230 241 \fB-0\fR
231 242 .ad
232 243 .RS 6n
233 244 Null separator mode. Instead of using white space or new lines to
234 245 delimit arguments, zero bytes are used. This is suitable for use with
235 246 the -print0 argument to \fBfind\fR(1).
236 247 .RE
237 248
238 249 .SH OPERANDS
239 250 .sp
240 251 .LP
241 252 The following operands are supported:
242 253 .sp
243 254 .ne 2
244 255 .na
245 256 \fB\fIutility\fR\fR
246 257 .ad
247 258 .RS 12n
248 259 The name of the utility to be invoked, found by search path using the
249 260 \fBPATH\fR environment variable. (ee \fBenviron\fR(5).) If \fIutility\fR is
250 261 omitted, the default is the \fBecho\fR(1) utility. If the \fIutility\fR operand
251 262 names any of the special built-in utilities in \fBshell_builtins\fR(1), the
252 263 results are undefined.
253 264 .RE
254 265
255 266 .sp
256 267 .ne 2
257 268 .na
258 269 \fB\fIargument\fR\fR
259 270 .ad
260 271 .RS 12n
261 272 An initial option or operand for the invocation of \fIutility\fR.
262 273 .RE
263 274
264 275 .SH USAGE
265 276 .sp
266 277 .LP
267 278 The \fB255\fR exit status allows a utility being used by \fBxargs\fR to tell
268 279 \fBxargs\fR to terminate if it knows no further invocations using the current
269 280 data stream succeeds. Thus, \fIutility\fR should explicitly \fBexit\fR with an
270 281 appropriate value to avoid accidentally returning with \fB255\fR.
271 282 .sp
272 283 .LP
273 284 Notice that input is parsed as lines. Blank characters separate arguments. If
274 285 \fBxargs\fR is used to bundle output of commands like \fBfind\fR \fIdir\fR
275 286 \fB-print\fR or \fBls\fR into commands to be executed, unexpected results are
276 287 likely if any filenames contain any blank characters or newline characters.
277 288 This can be fixed by using \fBfind\fR to call a script that converts each file
278 289 found into a quoted string that is then piped to \fBxargs\fR. Notice that the
279 290 quoting rules used by \fBxargs\fR are not the same as in the shell. They were
280 291 not made consistent here because existing applications depend on the current
281 292 rules and the shell syntax is not fully compatible with it. An easy rule that
282 293 can be used to transform any string into a quoted form that \fBxargs\fR
283 294 interprets correctly is to precede each character in the string with a
284 295 backslash (\fB\e\fR).
285 296 .sp
286 297 .LP
287 298 On implementations with a large value for \fB{ARG_MAX}\fR, \fBxargs\fR can
288 299 produce command lines longer than \fB{LINE_MAX}\fR. For invocation of
289 300 utilities, this is not a problem. If \fBxargs\fR is being used to create a text
290 301 file, users should explicitly set the maximum command line length with the
291 302 \fB-s\fR option.
292 303 .sp
293 304 .LP
294 305 The \fBxargs\fR utility returns exit status \fB127\fR if an error occurs so
295 306 that applications can distinguish "failure to find a utility" from "invoked
296 307 utility exited with an error indication." The value \fB127\fR was chosen
297 308 because it is not commonly used for other meanings; most utilities use small
298 309 values for "normal error conditions" and the values above \fB128\fR can be
299 310 confused with termination due to receipt of a signal. The value \fB126\fR was
300 311 chosen in a similar manner to indicate that the utility could be found, but not
301 312 invoked.
302 313 .SH EXAMPLES
303 314 .LP
304 315 \fBExample 1 \fRUsing the xargs command
305 316 .sp
306 317 .LP
307 318 The following example moves all files from directory \fB$1\fR to directory
308 319 \fB$2\fR, and echo each move command just before doing it:
309 320
310 321 .sp
311 322 .in +2
312 323 .nf
313 324 example% \fBls $1 | xargs -I {} -t mv $1/{} $2/{}\fR
314 325 .fi
315 326 .in -2
316 327 .sp
317 328
318 329 .sp
319 330 .LP
320 331 The following command combines the output of the parenthesised commands onto
321 332 one line, which is then written to the end of file \fBlog\fR:
322 333
323 334 .sp
324 335 .in +2
325 336 .nf
326 337 example% \fB(logname; date; printf "%s\en" "$0 $*") | xargs >>log\fR
327 338 .fi
328 339 .in -2
329 340 .sp
330 341
331 342 .sp
332 343 .LP
333 344 The following command invokes \fBdiff\fR with successive pairs of arguments
334 345 originally typed as command line arguments (assuming there are no embedded
335 346 blank characters in the elements of the original argument list):
336 347
337 348 .sp
338 349 .in +2
339 350 .nf
340 351 example% \fBprintf "%s\en" "$*" | xargs -n 2 -x diff\fR
341 352 .fi
342 353 .in -2
343 354 .sp
344 355
345 356 .sp
346 357 .LP
347 358 The user is asked which files in the current directory are to be archived. The
348 359 files are archived into \fBarch\fR \fB;\fR a, one at a time, or b, many at a
349 360 time:
350 361
351 362 .sp
352 363 .in +2
353 364 .nf
354 365 example% \fBls | xargs -p -L 1 ar -r arch
355 366 ls | xargs -p -L 1 | xargs ar -r arch\fR
356 367 .fi
357 368 .in -2
358 369 .sp
359 370
360 371 .sp
361 372 .LP
362 373 The following executes with successive pairs of arguments originally typed as
363 374 command line arguments:
364 375
365 376 .sp
366 377 .in +2
367 378 .nf
368 379 example% \fBecho $* | xargs -n 2 diff\fR
369 380 .fi
370 381 .in -2
371 382 .sp
372 383
373 384 .SH ENVIRONMENT VARIABLES
374 385 .sp
375 386 .LP
376 387 See \fBenviron\fR(5) for descriptions of the following environment variables
377 388 that affect the execution of \fBxargs\fR: \fBLANG\fR, \fBLC_ALL\fR,
378 389 \fBLC_COLLATE\fR, \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and \fBNLSPATH\fR.
379 390 .sp
380 391 .ne 2
381 392 .na
382 393 \fB\fBPATH\fR\fR
383 394 .ad
384 395 .RS 8n
385 396 Determine the location of \fIutility\fR.
386 397 .RE
387 398
388 399 .sp
389 400 .LP
390 401 Affirmative responses are processed using the extended regular expression
391 402 defined for the \fByesexpr\fR keyword in the \fBLC_MESSAGES\fR category of the
392 403 user's locale. The locale specified in the \fBLC_COLLATE\fR category defines
393 404 the behavior of ranges, equivalence classes, and multi-character collating
394 405 elements used in the expression defined for \fByesexpr\fR. The locale specified
395 406 in \fBLC_CTYPE\fR determines the locale for interpretation of sequences of
396 407 bytes of text data a characters, the behavior of character classes used in the
397 408 expression defined for the \fByesexpr\fR. See \fBlocale\fR(5).
398 409 .SH EXIT STATUS
399 410 .sp
400 411 .LP
401 412 The following exit values are returned:
402 413 .sp
403 414 .ne 2
404 415 .na
405 416 \fB\fB0\fR\fR
406 417 .ad
407 418 .RS 12n
408 419 All invocations of \fIutility\fR returned exit status \fB0\fR.
409 420 .RE
410 421
411 422 .sp
412 423 .ne 2
413 424 .na
414 425 \fB\fB1\(mi125\fR\fR
415 426 .ad
416 427 .RS 12n
417 428 A command line meeting the specified requirements could not be assembled, one
418 429 or more of the invocations of \fIutility\fR returned a non-zero exit status, or
419 430 some other error occurred.
420 431 .RE
421 432
422 433 .sp
423 434 .ne 2
424 435 .na
425 436 \fB\fB126\fR\fR
426 437 .ad
427 438 .RS 12n
428 439 The utility specified by \fIutility\fR was found but could not be invoked.
429 440 .RE
430 441
431 442 .sp
432 443 .ne 2
433 444 .na
434 445 \fB\fB127\fR\fR
435 446 .ad
436 447 .RS 12n
437 448 The utility specified by \fIutility\fR could not be found.
438 449 .RE
439 450
440 451 .sp
441 452 .LP
442 453 If a command line meeting the specified requirements cannot be assembled, the
443 454 utility cannot be invoked, an invocation of the utility is terminated by a
444 455 signal, or an invocation of the utility exits with exit status \fB255\fR, the
445 456 \fBxargs\fR utility writes a diagnostic message and exit without processing any
446 457 remaining input.
447 458 .SH ATTRIBUTES
448 459 .sp
449 460 .LP
450 461 See \fBattributes\fR(5) for descriptions of the following attributes:
451 462 .sp
452 463
453 464 .sp
454 465 .TS
455 466 box;
456 467 c | c
457 468 l | l .
458 469 ATTRIBUTE TYPE ATTRIBUTE VALUE
459 470 _
460 471 CSI Enabled
461 472 _
462 473 Interface Stability Standard
463 474 .TE
464 475
465 476 .SH SEE ALSO
466 477 .sp
467 478 .LP
468 479 \fBecho\fR(1), \fBshell_builtins\fR(1), \fBattributes\fR(5), \fBenviron\fR(5),
469 480 \fBstandards\fR(5)
↓ open down ↓ |
291 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX