xref: /freebsd/usr.bin/xargs/xargs.1 (revision ce4946daa5ce852d28008dac492029500ab2ee95)
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 June 6, 1993
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.Oo
49.Fl n Ar number
50.Op Fl x
51.Oc
52.Op Fl s Ar size
53.Op Fl t
54.Op Ar utility Op Ar argument ...
55.Sh DESCRIPTION
56The
57.Nm
58utility reads space, tab, newline and end-of-file delimited arguments
59from the standard input and executes the specified
60.Ar utility
61with them as
62arguments.
63.Pp
64The utility and any arguments specified on the command line are given
65to the
66.Ar utility
67upon each invocation, followed by some number of the arguments read
68from standard input.
69The
70.Ar utility
71is repeatedly executed until standard input is exhausted.
72.Pp
73Spaces, tabs and newlines may be embedded in arguments using single
74(``\ '\ '')
75or double (``"'') quotes or backslashes (``\e'').
76Single quotes escape all non-single quote characters, excluding newlines,
77up to the matching single quote.
78Double quotes escape all non-double quote characters, excluding newlines,
79up to the matching double quote.
80Any single character, including newlines, may be escaped by a backslash.
81.Pp
82The options are as follows:
83.Bl -tag -width indent
84.It Fl 0
85Change
86.Nm
87to expect NUL
88(``\\0'')
89characters as separators, instead of spaces and newlines.
90This is expected to be used in concert with the
91.Fl print0
92function in
93.Xr find 1 .
94.It Fl n Ar number
95Set the maximum number of arguments taken from standard input for each
96invocation of the utility.
97An invocation of
98.Ar utility
99will use less than
100.Ar number
101standard input arguments if the number of bytes accumulated (see the
102.Fl s
103option) exceeds the specified
104.Ar size
105or there are fewer than
106.Ar number
107arguments remaining for the last invocation of
108.Ar utility .
109The current default value for
110.Ar number
111is 5000.
112.It Fl s Ar size
113Set the maximum number of bytes for the command line length provided to
114.Ar utility .
115The sum of the length of the utility name, the arguments passed to
116.Ar utility
117(including
118.Dv NULL
119terminators) and the current environment will be less than or equal to
120this number.
121The current default value for
122.Ar size
123is
124.Dv ARG_MAX
125- 4096.
126.It Fl t
127Echo the command to be executed to standard error immediately before it
128is executed.
129.It Fl x
130Force
131.Nm
132to terminate immediately if a command line containing
133.Ar number
134arguments will not fit in the specified (or default) command line length.
135.El
136.Pp
137If no
138.Ar utility
139is specified,
140.Xr echo 1
141is used.
142.Pp
143Undefined behavior may occur if
144.Ar utility
145reads from the standard input.
146.Pp
147The
148.Nm
149utility exits immediately (without processing any further input) if a
150command line cannot be assembled,
151.Ar utility
152cannot be invoked, an invocation of the utility is terminated by a signal
153or an invocation of the utility exits with a value of 255.
154.Pp
155The
156.Nm
157utility exits with a value of 0 if no error occurs.
158If
159.Ar utility
160cannot be invoked,
161.Nm
162exits with a value of 127.
163If any other error occurs,
164.Nm
165exits with a value of 1.
166.Sh SEE ALSO
167.Xr echo 1 ,
168.Xr find 1 ,
169.Xr execvp 3
170.Sh STANDARDS
171The
172.Nm
173utility is expected to be
174.St -p1003.2
175compliant.
176.Sh BUGS
177If
178.Ar utility
179attempts to invoke another command such that the number of arguments or the
180size of the environment is increased, it risks
181.Xr execvp 3
182failing with
183.Er E2BIG .
184