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