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