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