source: trunk/essentials/sys-apps/findutils/xargs/xargs.1

Last change on this file was 3170, checked in by bird, 18 years ago

findutils 4.3.2

File size: 10.3 KB
Line 
1.TH XARGS 1 \" -*- nroff -*-
2.SH NAME
3xargs \- build and execute command lines from standard input
4.SH SYNOPSIS
5.B xargs
6[\-0prtx] [\-E eof-str] [\-e[eof-str]] [\-\-eof[=eof-str]] [\-\-null]
7[\-d delimiter] [\-\-delimiter delimiter]
8[\-I replace-str] [\-i[replace-str]] [\-\-replace[=replace-str]]
9[\-l[max-lines]] [\-L max-lines] [\-\-max\-lines[=max-lines]] [\-n max-args] [\-\-max\-args=max-args]
10[\-s max-chars] [\-\-max\-chars=max-chars] [\-P max-procs] [\-\-max\-procs=max-procs]
11[\-\-interactive] [\-\-verbose] [\-\-exit] [\-\-no\-run\-if\-empty]
12[\-\-arg\-file=file] [\-\-show\-limits] [\-\-version] [\-\-help]
13[command [initial-arguments]]
14.SH DESCRIPTION
15This manual page
16documents the GNU version of
17.BR xargs .
18.B xargs
19reads items from the standard input, delimited by blanks (which can be
20protected with double or single quotes or a backslash) or newlines,
21and executes the
22.I command
23(default is /bin/echo) one or more times with any
24.I initial-arguments
25followed by items read from standard input. Blank lines on the
26standard input are ignored.
27.P
28Because Unix filenames can contain blanks and newlines, this default
29behaviour is often problematic; filenames containing blanks
30and/or newlines are incorrectly processed by
31.BR xargs .
32In these situations it is better to use the `\-0' option, which
33prevents such problems. When using this option you will need to
34ensure that the program which produces the input for
35.B xargs
36also uses a null character as a separator. If that program is
37GNU
38.B find
39for example, the `\-print0' option does this for you.
40.P
41If any invocation of the command exits with a status of 255,
42.B xargs
43will stop immediately without reading any further input. An error
44message is issued on stderr when this happens.
45.SS OPTIONS
46.TP
47.I "\-\-arg\-file=file, \-a file"
48Read items from
49.I file
50instead of standard input. If you use this option, stdin remains
51unchanged when commands are run. Otherwise, stdin is redirected
52from
53.IR /dev/null .
54
55.TP
56.I "\-\-null, \-0"
57Input items are terminated by a null character instead of by
58whitespace, and the quotes and backslash are not special (every
59character is taken literally). Disables the end of file string, which
60is treated like any other argument. Useful when input items might
61contain white space, quote marks, or backslashes. The GNU find
62\-print0 option produces input suitable for this mode.
63.TP
64.I "\-\-delimiter=delim, \-d delim"
65Input items are terminated by the specified character. Quotes and
66backslash are not special; every character in the input is taken
67literally. Disables the end-of-file string, which is treated like any
68other argument. This can be used when the input consists of simply
69newline-separated items, although it is almost always better to design
70your program to use `\-\-null' where this is possible. The specified
71delimiter may be a single character, a C-style character escape such
72as
73.BR \en ,
74or an octal or hexadecimal escape code. Octal and hexadecimal
75escape codes are understood as for the
76.B printf
77command. Multibyte characters are not supported.
78
79.TP
80.I "\-Eeof-str"
81Set the end of file string to \fIeof-str\fR. If the end of file
82string occurs as a line of input, the rest of the input is ignored.
83If neither \-E nor \-e is used, no end of file string is used.
84.TP
85.I "\-\-eof[=eof-str], \-e[eof-str]"
86This option is a synonym for the `\-E' option. Use `\-E' instead,
87because it is POSIX compliant while this option is not. If
88\fIeof-str\fR is omitted, there is no end of file string. If neither
89\-E nor \-e is used, no end of file string is used.
90.TP
91.I "\-\-help"
92Print a summary of the options to
93.B xargs
94and exit.
95.TP
96.I "\-I replace-str"
97Replace occurrences of \fIreplace-str\fR in the initial-arguments with
98names read from standard input. Also, unquoted blanks do not
99terminate input items; instead the separator is the newline character.
100Implies \fI\-x\fP and \fI\-L 1\fP.
101.TP
102.I "\-\-replace[=replace-str], \-i[replace-str]"
103This option is a synonym for \-I\fIreplace-str\fR if \fIreplace-str\fR
104is specified, and for \-I{} otherwise. This option is deprecated; use
105\-I instead.
106.TP
107.I "\-L max-lines"
108Use at most \fImax-lines\fR nonblank input lines per command line.
109Trailing blanks cause an input line to be logically continued on the
110next input line. Implies \fI\-x\fR.
111.TP
112.I "\-\-max-lines[=max-lines], \-l[max-lines]"
113Synonym for the \-L option. Unlike \-L, the \fImax-lines\fR argument
114is optional. If \fImax-args\fR is not specified, it defaults to one.
115The \-l option is deprecated since the POSIX standard specifies \-L
116instead.
117.TP
118.I "\-\-max\-args=max-args, \-n max-args"
119Use at most \fImax-args\fR arguments per command line. Fewer than
120\fImax-args\fR arguments will be used if the size (see the \-s option)
121is exceeded, unless the \-x option is given, in which case \fBxargs\fR
122will exit.
123.TP
124.I "\-\-interactive, \-p"
125Prompt the user about whether to run each command line and read a line
126from the terminal. Only run the command line if the response starts
127with `y' or `Y'. Implies \fI\-t\fR.
128.TP
129.I "\-\-no\-run\-if\-empty, \-r"
130If the standard input does not contain any nonblanks, do not run the
131command. Normally, the command is run once even if there is no input.
132This option is a GNU extension.
133.TP
134.I "\-\-max\-chars=max-chars, \-s max-chars"
135Use at most \fImax-chars\fR characters per command line, including the
136command and initial-arguments and the terminating nulls at the ends of
137the argument strings. The default is 131072 characters, not including
138the size of the environment variables (which are provided for
139separately so that it doesn't matter if your environment variables
140take up more than 131072 bytes). The operating system places limits
141on the values that you can usefully specify, and if you exceed these a
142warning message is printed and the value actually used is set to the
143appropriate upper or lower limit.
144.TP
145.I "\-\-verbose, \-t"
146Print the command line on the standard error output before executing
147it.
148.TP
149.I "\-\-version"
150Print the version number of
151.B xargs
152and exit.
153.TP
154.I "\-\-show\\-limits"
155Display the limits on the command-line length which are imposed by the
156operating system,
157.BR xargs '
158choice of buffer size and the
159.I \-s
160option. Pipe the input from
161.B /dev/null
162(and perhaps specify
163.BR --no-run-if-empty )
164if you don't want
165.B xargs
166to do anything.
167.TP
168.I "\-\-exit, \-x"
169Exit if the size (see the \fI\-s\fR option) is exceeded.
170.TP
171.I "\-\-max\-procs=max-procs, \-P max-procs"
172Run up to \fImax-procs\fR processes at a time; the default is 1. If
173\fImax-procs\fR is 0, \fBxargs\fR will run as many processes as
174possible at a time. Use the \fI\-n\fR option with \fI\-P\fR;
175otherwise chances are that only one exec will be done.
176.SH "EXAMPLES"
177.nf
178.B find /tmp \-name core \-type f \-print | xargs /bin/rm \-f
179
180.fi
181Find files named
182.B core
183in or below the directory
184.B /tmp
185and delete them. Note that this will work incorrectly if there are
186any filenames containing newlines or spaces.
187.P
188.B find /tmp \-name core \-type f \-print0 | xargs \-0 /bin/rm \-f
189
190.fi
191Find files named
192.B core
193in or below the directory
194.B /tmp
195and delete them, processing filenames in such a way that file or
196directory names containing spaces or newlines are correctly handled.
197.P
198.nf
199.B cut \-d: \-f1 < /etc/passwd | sort | xargs echo
200
201.fi
202Generates a compact listing of all the users on the system.
203.SH "EXIT STATUS"
204.B xargs
205exits with the following status:
206.nf
2070 if it succeeds
208123 if any invocation of the command exited with status 1-125
209124 if the command exited with status 255
210125 if the command is killed by a signal
211126 if the command cannot be run
212127 if the command is not found
2131 if some other error occurred.
214.fi
215.P
216Exit codes greater than 128 are used by the shell to indicate that
217a program died due to a fatal signal.
218.SH "STANDARDS CONFORMANCE"
219As of GNU xargs version 4.2.9, the default behaviour of
220.B xargs
221is not to have a logical end-of-file marker. POSIX (IEEE Std 1003.1,
2222004 Edition) allows this.
223.P
224The \-l and \-i options appear in the 1997 version of the POSIX
225standard, but do not appear in the 2004 version of the standard.
226Therefore you should use \-L and \-I instead, respectively.
227
228.SH "SEE ALSO"
229\fBfind\fP(1), \fBlocate\fP(1), \fBlocatedb\fP(5), \fBupdatedb\fP(1),
230\fBFinding Files\fP (on-line in Info, or printed)
231.SH "BUGS"
232The \-L option is incompatible with the \-I option, but perhaps should not be.
233.P
234It is not possible for
235.B xargs
236to be used securely, since there will always be a time gap between the
237production of the list of input files and their use in the commands
238that
239.B xargs
240issues. If other users have access to the system, they can manipulate
241the filesystem during this time window to force the action of the
242commands
243.B xargs
244runs to apply to files that you didn't intend. For a more detailed
245discussion of this and related problems, please refer to the
246``Security Considerations'' chapter in the findutils Texinfo
247documentation. The \-execdir option of
248.B find
249can often be used as a more secure alternative.
250
251When you use the \-I option, each line read from the input is buffered
252internally. This means that there is an upper limit on the length
253of input line that
254.B xargs
255will accept when used with the \-I option. To work around this
256limitation, you can use the \-s option to increase the amount of
257buffer space that
258.B xargs
259uses, and you can also use an extra invocation of
260.B xargs
261to ensure that very long lines do not occur.
262For example:
263.P
264.B somecommand | xargs \-s 50000 echo | xargs \-I '{}' \-s 100000 rm '{}'
265.P
266Here, the first invocation of
267.B xargs
268has no input line length limit
269because it doesn't use the \-i option. The second invocation of
270.B xargs
271does have such a limit, but we have ensured that the it never encounters
272a line which is longer than it can handle. This is not an ideal
273solution. Instead, the \-i option should not impose a line length
274limit, which is why this discussion appears in the BUGS section.
275The problem doesn't occur with the output of
276.BR find (1)
277because it emits just one filename per line.
278.P
279The best way to report a bug is to use the form at
280http://savannah.gnu.org/bugs/?group=findutils.
281The reason for this is that you will then be able to track progress in
282fixing the problem. Other comments about \fBxargs\fP(1) and about
283the findutils package in general can be sent to the
284.I bug\-findutils
285mailing list. To join the list, send email to
286.IR bug\-findutils\-request@gnu.org .
Note: See TracBrowser for help on using the repository browser.