]>
Commit | Line | Data |
---|---|---|
1 | .\" Copyright (c) 1990, 1991, 1993 | |
2 | .\" The Regents of the University of California. All rights reserved. | |
3 | .\" | |
4 | .\" This code is derived from software contributed to Berkeley by | |
5 | .\" John B. Roll Jr. and the Institute of Electrical and Electronics | |
6 | .\" Engineers, Inc. | |
7 | .\" | |
8 | .\" Redistribution and use in source and binary forms, with or without | |
9 | .\" modification, are permitted provided that the following conditions | |
10 | .\" are met: | |
11 | .\" 1. Redistributions of source code must retain the above copyright | |
12 | .\" notice, this list of conditions and the following disclaimer. | |
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
14 | .\" notice, this list of conditions and the following disclaimer in the | |
15 | .\" documentation and/or other materials provided with the distribution. | |
16 | .\" 3. Neither the name of the University nor the names of its contributors | |
17 | .\" may be used to endorse or promote products derived from this software | |
18 | .\" without specific prior written permission. | |
19 | .\" | |
20 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
21 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
22 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
23 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
24 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
25 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
26 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
27 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
28 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
30 | .\" SUCH DAMAGE. | |
31 | .\" | |
32 | .\" @(#)xargs.1 8.1 (Berkeley) 6/6/93 | |
33 | .\" $FreeBSD: src/usr.bin/xargs/xargs.1,v 1.34 2005/05/21 09:55:09 ru Exp $ | |
34 | .\" $xMach: xargs.1,v 1.2 2002/02/23 05:23:37 tim Exp $ | |
35 | .\" | |
36 | .Dd August 4, 2015 | |
37 | .Dt XARGS 1 | |
38 | .Os | |
39 | .Sh NAME | |
40 | .Nm xargs | |
41 | .Nd "construct argument list(s) and execute utility" | |
42 | .Sh SYNOPSIS | |
43 | .Nm | |
44 | .Op Fl 0oprt | |
45 | .Op Fl E Ar eofstr | |
46 | .Oo | |
47 | .Fl I Ar replstr | |
48 | .Op Fl R Ar replacements | |
49 | .Op Fl S Ar replsize | |
50 | .Oc | |
51 | .Op Fl J Ar replstr | |
52 | .Op Fl L Ar number | |
53 | .Oo | |
54 | .Fl n Ar number | |
55 | .Op Fl x | |
56 | .Oc | |
57 | .Op Fl P Ar maxprocs | |
58 | .Op Fl s Ar size | |
59 | .Op Ar utility Op Ar argument ... | |
60 | .Sh DESCRIPTION | |
61 | The | |
62 | .Nm | |
63 | utility reads space, tab, newline and end-of-file delimited strings | |
64 | from the standard input and executes | |
65 | .Ar utility | |
66 | with the strings as | |
67 | arguments. | |
68 | .Pp | |
69 | Any arguments specified on the command line are given to | |
70 | .Ar utility | |
71 | upon each invocation, followed by some number of the arguments read | |
72 | from the standard input of | |
73 | .Nm . | |
74 | This is repeated until standard input is exhausted. | |
75 | .Pp | |
76 | Spaces, tabs and newlines may be embedded in arguments using single | |
77 | (``\ '\ '') | |
78 | or double (``"'') quotes or backslashes (``\e''). | |
79 | Single quotes escape all non-single quote characters, excluding newlines, | |
80 | up to the matching single quote. | |
81 | Double quotes escape all non-double quote characters, excluding newlines, | |
82 | up to the matching double quote. | |
83 | Any single character, including newlines, may be escaped by a backslash. | |
84 | .Pp | |
85 | The options are as follows: | |
86 | .Bl -tag -width indent | |
87 | .It Fl 0 | |
88 | Change | |
89 | .Nm | |
90 | to expect NUL | |
91 | (``\\0'') | |
92 | characters as separators, instead of spaces and newlines. | |
93 | This is expected to be used in concert with the | |
94 | .Fl print0 | |
95 | function in | |
96 | .Xr find 1 . | |
97 | .It Fl E Ar eofstr | |
98 | Use | |
99 | .Ar eofstr | |
100 | as a logical EOF marker. | |
101 | .It Fl I Ar replstr | |
102 | Execute | |
103 | .Ar utility | |
104 | for each input line, replacing one or more occurrences of | |
105 | .Ar replstr | |
106 | in up to | |
107 | .Ar replacements | |
108 | (or 5 if no | |
109 | .Fl R | |
110 | flag is specified) arguments to | |
111 | .Ar utility | |
112 | with the entire line of input. | |
113 | The resulting arguments, after replacement is done, will not be allowed to grow | |
114 | beyond | |
115 | .Ar replsize | |
116 | (or 255 if no | |
117 | .Fl S | |
118 | flag is specified) | |
119 | bytes; this is implemented by concatenating as much of the argument | |
120 | containing | |
121 | .Ar replstr | |
122 | as possible, to the constructed arguments to | |
123 | .Ar utility , | |
124 | up to | |
125 | .Ar replsize | |
126 | bytes. | |
127 | The size limit does not apply to arguments to | |
128 | .Ar utility | |
129 | which do not contain | |
130 | .Ar replstr , | |
131 | and furthermore, no replacement will be done on | |
132 | .Ar utility | |
133 | itself. | |
134 | Implies | |
135 | .Fl x . | |
136 | .It Fl J Ar replstr | |
137 | If this option is specified, | |
138 | .Nm | |
139 | will use the data read from standard input to replace the first occurrence of | |
140 | .Ar replstr | |
141 | instead of appending that data after all other arguments. | |
142 | This option will not affect how many arguments will be read from input | |
143 | .Pq Fl n , | |
144 | or the size of the command(s) | |
145 | .Nm | |
146 | will generate | |
147 | .Pq Fl s . | |
148 | The option just moves where those arguments will be placed in the command(s) | |
149 | that are executed. | |
150 | The | |
151 | .Ar replstr | |
152 | must show up as a distinct | |
153 | .Ar argument | |
154 | to | |
155 | .Nm . | |
156 | It will not be recognized if, for instance, it is in the middle of a | |
157 | quoted string. | |
158 | Furthermore, only the first occurrence of the | |
159 | .Ar replstr | |
160 | will be replaced. | |
161 | For example, the following command will copy the list of files and | |
162 | directories which start with an uppercase letter in the current | |
163 | directory to | |
164 | .Pa destdir : | |
165 | .Pp | |
166 | .Dl /bin/ls -1d [A-Z]* | xargs -J % cp -Rp % destdir | |
167 | .It Fl L Ar number | |
168 | Call | |
169 | .Ar utility | |
170 | for every | |
171 | .Ar number | |
172 | non-empty lines read. | |
173 | A line ending with a space continues to the next non-empty line. | |
174 | If EOF is reached and fewer lines have been read than | |
175 | .Ar number | |
176 | then | |
177 | .Ar utility | |
178 | will be called with the available lines. | |
179 | The | |
180 | .Fl L | |
181 | and | |
182 | .Fl n | |
183 | options are mutually-exclusive; the last one given will be used. | |
184 | .It Fl n Ar number | |
185 | Set the maximum number of arguments taken from standard input for each | |
186 | invocation of | |
187 | .Ar utility . | |
188 | An invocation of | |
189 | .Ar utility | |
190 | will use less than | |
191 | .Ar number | |
192 | standard input arguments if the number of bytes accumulated (see the | |
193 | .Fl s | |
194 | option) exceeds the specified | |
195 | .Ar size | |
196 | or there are fewer than | |
197 | .Ar number | |
198 | arguments remaining for the last invocation of | |
199 | .Ar utility . | |
200 | The current default value for | |
201 | .Ar number | |
202 | is 5000. | |
203 | .It Fl o | |
204 | Reopen stdin as | |
205 | .Pa /dev/tty | |
206 | in the child process before executing the command. | |
207 | This is useful if you want | |
208 | .Nm | |
209 | to run an interactive application. | |
210 | .It Fl P Ar maxprocs | |
211 | Parallel mode: run at most | |
212 | .Ar maxprocs | |
213 | invocations of | |
214 | .Ar utility | |
215 | at once. | |
216 | If | |
217 | .Ar maxprocs | |
218 | is set to 0, | |
219 | .Nm | |
220 | will run as many processes as possible. | |
221 | .It Fl p | |
222 | Echo each command to be executed and ask the user whether it should be | |
223 | executed. | |
224 | An affirmative response, | |
225 | .Ql y | |
226 | in the POSIX locale, | |
227 | causes the command to be executed, any other response causes it to be | |
228 | skipped. | |
229 | No commands are executed if the process is not attached to a terminal. | |
230 | .It Fl r | |
231 | Compatibility with GNU | |
232 | .Nm . | |
233 | The GNU version of | |
234 | .Nm | |
235 | runs the | |
236 | .Ar utility | |
237 | argument at least once, even if | |
238 | .Nm | |
239 | input is empty, and it supports a | |
240 | .Fl r | |
241 | option to inhibit this behavior. | |
242 | The | |
243 | .Fx | |
244 | version of | |
245 | .Nm | |
246 | does not run the | |
247 | .Ar utility | |
248 | argument on empty input, but it supports the | |
249 | .Fl r | |
250 | option for command-line compatibility with GNU | |
251 | .Nm , | |
252 | but the | |
253 | .Fl r | |
254 | option does nothing in the | |
255 | .Fx | |
256 | version of | |
257 | .Nm . | |
258 | .It Fl R Ar replacements | |
259 | Specify the maximum number of arguments that | |
260 | .Fl I | |
261 | will do replacement in. | |
262 | If | |
263 | .Ar replacements | |
264 | is negative, the number of arguments in which to replace is unbounded. | |
265 | .It Fl S Ar replsize | |
266 | Specify the amount of space (in bytes) that | |
267 | .Fl I | |
268 | can use for replacements. | |
269 | The default for | |
270 | .Ar replsize | |
271 | is 255. | |
272 | .It Fl s Ar size | |
273 | Set the maximum number of bytes for the command line length provided to | |
274 | .Ar utility . | |
275 | The sum of the length of the utility name, the arguments passed to | |
276 | .Ar utility | |
277 | (including | |
278 | .Dv NULL | |
279 | terminators) and the current environment will be less than or equal to | |
280 | this number. | |
281 | The current default value for | |
282 | .Ar size | |
283 | is | |
284 | .Dv ARG_MAX | |
285 | - 4096. | |
286 | .It Fl t | |
287 | Echo the command to be executed to standard error immediately before it | |
288 | is executed. | |
289 | .It Fl x | |
290 | Force | |
291 | .Nm | |
292 | to terminate immediately if a command line containing | |
293 | .Ar number | |
294 | arguments will not fit in the specified (or default) command line length. | |
295 | .El | |
296 | .Pp | |
297 | If | |
298 | .Ar utility | |
299 | is omitted, | |
300 | .Xr echo 1 | |
301 | is used. | |
302 | .Pp | |
303 | Undefined behavior may occur if | |
304 | .Ar utility | |
305 | reads from the standard input. | |
306 | .Pp | |
307 | The | |
308 | .Nm | |
309 | utility exits immediately (without processing any further input) if a | |
310 | command line cannot be assembled, | |
311 | .Ar utility | |
312 | cannot be invoked, an invocation of | |
313 | .Ar utility | |
314 | is terminated by a signal, | |
315 | or an invocation of | |
316 | .Ar utility | |
317 | exits with a value of 255, the | |
318 | .Nm | |
319 | utility stops processing input and exits after all invocations of | |
320 | .Ar utility | |
321 | finish processing. | |
322 | .Sh LEGACY DESCRIPTION | |
323 | In legacy mode, the | |
324 | .Fl L | |
325 | option treats all newlines as end-of-line, regardless of whether | |
326 | the line is empty or ends with a space. | |
327 | In addition, the | |
328 | .Fl L | |
329 | and | |
330 | .Fl n | |
331 | options are not mutually-exclusive. | |
332 | .Pp | |
333 | For more information about legacy mode, see | |
334 | .Xr compat 5 . | |
335 | .Sh EXIT STATUS | |
336 | The | |
337 | .Nm | |
338 | utility exits with a value of 0 if no error occurs. | |
339 | If | |
340 | .Ar utility | |
341 | cannot be found, | |
342 | .Nm | |
343 | exits with a value of 127, otherwise if | |
344 | .Ar utility | |
345 | cannot be executed, | |
346 | .Nm | |
347 | exits with a value of 126. | |
348 | If any other error occurs, | |
349 | .Nm | |
350 | exits with a value of 1. | |
351 | .Sh SEE ALSO | |
352 | .Xr echo 1 , | |
353 | .Xr find 1 , | |
354 | .Xr execvp 3 , | |
355 | .Xr compat 5 | |
356 | .Sh STANDARDS | |
357 | The | |
358 | .Nm | |
359 | utility is expected to be | |
360 | .St -p1003.2 | |
361 | compliant. | |
362 | The | |
363 | .Fl J , o , P, R | |
364 | and | |
365 | .Fl S | |
366 | options are non-standard | |
367 | .Fx | |
368 | extensions which may not be available on other operating systems. | |
369 | .Sh HISTORY | |
370 | The | |
371 | .Nm | |
372 | utility appeared in PWB UNIX. | |
373 | .Sh BUGS | |
374 | If | |
375 | .Ar utility | |
376 | attempts to invoke another command such that the number of arguments or the | |
377 | size of the environment is increased, it risks | |
378 | .Xr execvp 3 | |
379 | failing with | |
380 | .Er E2BIG . | |
381 | .Pp | |
382 | The | |
383 | .Nm | |
384 | utility does not take multibyte characters into account when performing | |
385 | string comparisons for the | |
386 | .Fl I | |
387 | and | |
388 | .Fl J | |
389 | options, which may lead to incorrect results in some locales. |