]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/xargs/xargs.1
This commit was generated by cvs2svn to compensate for changes in r92899,
[FreeBSD/FreeBSD.git] / usr.bin / xargs / xargs.1
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. All advertising materials mentioning features or use of this software
17 .\"    must display the following acknowledgement:
18 .\"     This product includes software developed by the University of
19 .\"     California, Berkeley and its contributors.
20 .\" 4. Neither the name of the University nor the names of its contributors
21 .\"    may be used to endorse or promote products derived from this software
22 .\"    without specific prior written permission.
23 .\"
24 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" SUCH DAMAGE.
35 .\"
36 .\"     @(#)xargs.1     8.1 (Berkeley) 6/6/93
37 .\" $FreeBSD$
38 .\"
39 .Dd May 7, 2001
40 .Dt XARGS 1
41 .Os
42 .Sh NAME
43 .Nm xargs
44 .Nd "construct argument list(s) and execute utility"
45 .Sh SYNOPSIS
46 .Nm
47 .Op Fl 0
48 .Op Fl J Ar replstr
49 .Oo
50 .Fl n Ar number
51 .Op Fl x
52 .Oc
53 .Op Fl s Ar size
54 .Op Fl t
55 .Op Ar utility Op Ar argument ...
56 .Sh DESCRIPTION
57 The
58 .Nm
59 utility reads space, tab, newline and end-of-file delimited arguments
60 from the standard input and executes the specified
61 .Ar utility
62 with them as
63 arguments.
64 .Pp
65 The utility and any arguments specified on the command line are given
66 to the
67 .Ar utility
68 upon each invocation, followed by some number of the arguments read
69 from standard input.
70 The
71 .Ar utility
72 is repeatedly executed until standard input is exhausted.
73 .Pp
74 Spaces, tabs and newlines may be embedded in arguments using single
75 (``\ '\ '')
76 or double (``"'') quotes or backslashes (``\e'').
77 Single quotes escape all non-single quote characters, excluding newlines,
78 up to the matching single quote.
79 Double quotes escape all non-double quote characters, excluding newlines,
80 up to the matching double quote.
81 Any single character, including newlines, may be escaped by a backslash.
82 .Pp
83 The options are as follows:
84 .Bl -tag -width indent
85 .It Fl 0
86 Change
87 .Nm
88 to expect NUL
89 (``\\0'')
90 characters as separators, instead of spaces and newlines.
91 This is expected to be used in concert with the
92 .Fl print0
93 function in
94 .Xr find 1 .
95 .It Fl J Ar replstr
96 If this option is specified,
97 .Nm
98 will use the data read from standard input to replace the first occurrence of
99 .Ar replstr
100 instead of appending that data after all other arguments.
101 This option will not effect how many arguments will be read from input
102 .Pq Fl n ,
103 or the size of the command(s)
104 .Nm
105 will generate
106 .Pq Fl s .
107 The option just moves where those arguments will be placed in the command(s)
108 that are executed.
109 The
110 .Ar replstr
111 must show up as a distinct
112 .Ar argument
113 to
114 .Nm .
115 It will not be recognized if, for instance, it is in the middle of a
116 quoted string.
117 Furthermore, only the first occurrence of the
118 .Ar replstr
119 will be replaced.
120 For example, the following command will copy the list of files and
121 directories which start with an uppercase letter in the current
122 directory to
123 .Pa destdir :
124 .Pp
125 .Dl /bin/ls -1d [A-Z]* | xargs -J [] cp -rp [] destdir
126 .Pp
127 .It Fl n Ar number
128 Set the maximum number of arguments taken from standard input for each
129 invocation of the utility.
130 An invocation of
131 .Ar utility
132 will use less than
133 .Ar number
134 standard input arguments if the number of bytes accumulated (see the
135 .Fl s
136 option) exceeds the specified
137 .Ar size
138 or there are fewer than
139 .Ar number
140 arguments remaining for the last invocation of
141 .Ar utility .
142 The current default value for
143 .Ar number
144 is 5000.
145 .It Fl s Ar size
146 Set the maximum number of bytes for the command line length provided to
147 .Ar utility .
148 The sum of the length of the utility name, the arguments passed to
149 .Ar utility
150 (including
151 .Dv NULL
152 terminators) and the current environment will be less than or equal to
153 this number.
154 The current default value for
155 .Ar size
156 is
157 .Dv ARG_MAX
158 - 4096.
159 .It Fl t
160 Echo the command to be executed to standard error immediately before it
161 is executed.
162 .It Fl x
163 Force
164 .Nm
165 to terminate immediately if a command line containing
166 .Ar number
167 arguments will not fit in the specified (or default) command line length.
168 .El
169 .Pp
170 If no
171 .Ar utility
172 is specified,
173 .Xr echo 1
174 is used.
175 .Pp
176 Undefined behavior may occur if
177 .Ar utility
178 reads from the standard input.
179 .Pp
180 The
181 .Nm
182 utility exits immediately (without processing any further input) if a
183 command line cannot be assembled,
184 .Ar utility
185 cannot be invoked, an invocation of the utility is terminated by a signal
186 or an invocation of the utility exits with a value of 255.
187 .Pp
188 The
189 .Nm
190 utility exits with a value of 0 if no error occurs.
191 If
192 .Ar utility
193 cannot be invoked,
194 .Nm
195 exits with a value of 127.
196 If any other error occurs,
197 .Nm
198 exits with a value of 1.
199 .Sh SEE ALSO
200 .Xr echo 1 ,
201 .Xr find 1 ,
202 .Xr execvp 3
203 .Sh STANDARDS
204 The
205 .Nm
206 utility is expected to be
207 .St -p1003.2
208 compliant.
209 The
210 .Fl J
211 option is a non-standard
212 .Fx
213 extension which may not be available on other operating systems.
214 .Sh BUGS
215 If
216 .Ar utility
217 attempts to invoke another command such that the number of arguments or the
218 size of the environment is increased, it risks
219 .Xr execvp 3
220 failing with
221 .Er E2BIG .