xref: /netbsd-src/usr.bin/xargs/xargs.1 (revision 3b01aba77a7a698587faaae455bbfe740923c1f5)
1.\"	$NetBSD: xargs.1,v 1.12 2000/09/04 07:35:20 kleink Exp $
2.\"
3.\" Copyright (c) 1990, 1991, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" John B. Roll Jr. and the Institute of Electrical and Electronics
8.\" Engineers, Inc.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\"    notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in the
17.\"    documentation and/or other materials provided with the distribution.
18.\" 3. All advertising materials mentioning features or use of this software
19.\"    must display the following acknowledgement:
20.\"	This product includes software developed by the University of
21.\"	California, Berkeley and its contributors.
22.\" 4. Neither the name of the University nor the names of its contributors
23.\"    may be used to endorse or promote products derived from this software
24.\"    without specific prior written permission.
25.\"
26.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36.\" SUCH DAMAGE.
37.\"
38.\"	@(#)xargs.1	8.1 (Berkeley) 6/6/93
39.\"
40.Dd December 21, 1999
41.Dt XARGS 1
42.Os
43.Sh NAME
44.Nm xargs
45.Nd "construct argument list(s) and execute utility"
46.Sh SYNOPSIS
47.Nm
48.Op Fl 0
49.Op Fl I Ar replstr
50.Op Fl p
51.Op Fl t
52.Oo Op Fl x
53.Fl n Ar number
54.Oc
55.Op Fl s Ar size
56.Op Ar utility Op Ar arguments ...
57.Sh DESCRIPTION
58The
59.Nm
60utility reads space, tab, newline and end-of-file delimited arguments
61from the standard input and executes the specified
62.Ar utility
63with them as
64arguments.
65.Pp
66The utility and any arguments specified on the command line are given
67to the
68.Ar utility
69upon each invocation, followed by some number of the arguments read
70from standard input.
71The
72.Ar utility
73is repeatedly executed until standard input is exhausted.
74.Pp
75Spaces, tabs and newlines may be embedded in arguments using single
76(``\ '\ '')
77or double (``"'') quotes or backslashes (``\e'').
78Single quotes escape all non-single quote characters, excluding newlines,
79up to the matching single quote.
80Double quotes escape all non-double quote characters, excluding newlines,
81up to the matching double quote.
82Any single character, including newlines, may be escaped by a backslash.
83.Pp
84The options are as follows:
85.Bl -tag -width Fl
86.It Fl 0
87Use NUL
88(``\e0'')
89instead of whitespace as the argument separator.
90This can be used in conjuction with the
91.Fl print0
92option of
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 p
113Prompt mode: immediately before each command execution the user is prompted
114whether to execute the command instance.  If an affirmative response is read
115from
116.Pa /dev/tty
117the command will be executed; otherwise this particular invocation will be
118skipped.
119This option implies the
120.Fl t
121option.
122.It Fl s Ar size
123Set the maximum number of bytes for the command line length provided to
124.Ar utility .
125The sum of the length of the utility name and the arguments passed to
126.Ar utility
127(including
128.Dv NULL
129terminators) will be less than or equal to this number.
130The current default value for
131.Ar size
132is
133.Dv ARG_MAX
134- 4096.
135.It Fl t
136Echo the command to be executed to standard error immediately before it
137is executed.
138.It Fl x
139Force
140.Nm
141to terminate immediately if a command line containing
142.Ar number
143arguments will not fit in the specified (or default) command line length.
144.El
145.Pp
146If no
147.Ar utility
148is specified,
149.Xr echo 1
150is used.
151.Pp
152Undefined behavior may occur if
153.Ar utility
154reads from the standard input.
155.Pp
156The
157.Nm
158utility exits immediately (without processing any further input) if a
159command line cannot be assembled,
160.Ar utility
161cannot be invoked, an invocation of the utility is terminated by a signal
162or an invocation of the utility exits with a value of 255.
163.Sh FILES
164.Bl -tag -width /dev/tty -compact
165.It Pa /dev/tty
166used to read responses in prompt mode
167.El
168.Sh EXIT STATUS
169.Nm
170exits with one of the following values:
171.Bl -tag -width Ds -compact
172.It 0
173All invocations of
174.Ar utility
175returned a zero exit status.
176.It 123
177One or more invocations of
178.Ar utility
179returned a nonzero exit status.
180.It 124
181The
182.Ar utility
183exited with a 255 exit status.
184.It 125
185The
186.Ar utility
187was killed or stopped by a signal.
188.It 126
189The
190.Ar utility
191was found but could not be invoked.
192.It 127
193The
194.Ar utility
195could not be found.
196.It 1
197Some other error occurred.
198.El
199.Sh SEE ALSO
200.Xr echo 1 ,
201.Xr find 1
202.Sh STANDARDS
203The
204.Nm
205utility is expected to be
206.St -p1003.2
207compliant.
208.Sh HISTORY
209The
210.Nm xargs
211command appeared in PWB Unix 1.0.
212It made its first BSD appearance in the 4.3 Reno release.
213.Pp
214The meaning of 123, 124, and 125 exit values and the
215.Fl 0
216option were taken from GNU xargs.
217