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] [\-\-no\-run\-if\-empty]
|
---|
12 | [\-\-arg\-file=file] [\-\-show\-limits] [\-\-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.
|
---|
27 | .P
|
---|
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.
|
---|
40 | .P
|
---|
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 .
|
---|
54 |
|
---|
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.
|
---|
78 |
|
---|
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.
|
---|
101 | .TP
|
---|
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.
|
---|
106 | .TP
|
---|
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.
|
---|
111 | .TP
|
---|
112 | .I "\-\-max-lines[=max-lines], \-l[max-lines]"
|
---|
113 | Synonym for the \-L option. Unlike \-L, the \fImax-lines\fR argument
|
---|
114 | is optional. If \fImax-args\fR is not specified, it defaults to one.
|
---|
115 | The \-l option is deprecated since the POSIX standard specifies \-L
|
---|
116 | instead.
|
---|
117 | .TP
|
---|
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.
|
---|
123 | .TP
|
---|
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.
|
---|
128 | .TP
|
---|
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.
|
---|
133 | .TP
|
---|
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.
|
---|
144 | .TP
|
---|
145 | .I "\-\-verbose, \-t"
|
---|
146 | Print the command line on the standard error output before executing
|
---|
147 | it.
|
---|
148 | .TP
|
---|
149 | .I "\-\-version"
|
---|
150 | Print the version number of
|
---|
151 | .B xargs
|
---|
152 | and exit.
|
---|
153 | .TP
|
---|
154 | .I "\-\-show\\-limits"
|
---|
155 | Display the limits on the command-line length which are imposed by the
|
---|
156 | operating system,
|
---|
157 | .BR xargs '
|
---|
158 | choice of buffer size and the
|
---|
159 | .I \-s
|
---|
160 | option. Pipe the input from
|
---|
161 | .B /dev/null
|
---|
162 | (and perhaps specify
|
---|
163 | .BR --no-run-if-empty )
|
---|
164 | if you don't want
|
---|
165 | .B xargs
|
---|
166 | to do anything.
|
---|
167 | .TP
|
---|
168 | .I "\-\-exit, \-x"
|
---|
169 | Exit if the size (see the \fI\-s\fR option) is exceeded.
|
---|
170 | .TP
|
---|
171 | .I "\-\-max\-procs=max-procs, \-P max-procs"
|
---|
172 | Run 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
|
---|
174 | possible at a time. Use the \fI\-n\fR option with \fI\-P\fR;
|
---|
175 | otherwise 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
|
---|
181 | Find files named
|
---|
182 | .B core
|
---|
183 | in or below the directory
|
---|
184 | .B /tmp
|
---|
185 | and delete them. Note that this will work incorrectly if there are
|
---|
186 | any filenames containing newlines or spaces.
|
---|
187 | .P
|
---|
188 | .B find /tmp \-name core \-type f \-print0 | xargs \-0 /bin/rm \-f
|
---|
189 |
|
---|
190 | .fi
|
---|
191 | Find files named
|
---|
192 | .B core
|
---|
193 | in or below the directory
|
---|
194 | .B /tmp
|
---|
195 | and delete them, processing filenames in such a way that file or
|
---|
196 | directory 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
|
---|
202 | Generates a compact listing of all the users on the system.
|
---|
203 | .SH "EXIT STATUS"
|
---|
204 | .B xargs
|
---|
205 | exits with the following status:
|
---|
206 | .nf
|
---|
207 | 0 if it succeeds
|
---|
208 | 123 if any invocation of the command exited with status 1-125
|
---|
209 | 124 if the command exited with status 255
|
---|
210 | 125 if the command is killed by a signal
|
---|
211 | 126 if the command cannot be run
|
---|
212 | 127 if the command is not found
|
---|
213 | 1 if some other error occurred.
|
---|
214 | .fi
|
---|
215 | .P
|
---|
216 | Exit codes greater than 128 are used by the shell to indicate that
|
---|
217 | a program died due to a fatal signal.
|
---|
218 | .SH "STANDARDS CONFORMANCE"
|
---|
219 | As of GNU xargs version 4.2.9, the default behaviour of
|
---|
220 | .B xargs
|
---|
221 | is not to have a logical end-of-file marker. POSIX (IEEE Std 1003.1,
|
---|
222 | 2004 Edition) allows this.
|
---|
223 | .P
|
---|
224 | The \-l and \-i options appear in the 1997 version of the POSIX
|
---|
225 | standard, but do not appear in the 2004 version of the standard.
|
---|
226 | Therefore 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"
|
---|
232 | The \-L option is incompatible with the \-I option, but perhaps should not be.
|
---|
233 | .P
|
---|
234 | It is not possible for
|
---|
235 | .B xargs
|
---|
236 | to be used securely, since there will always be a time gap between the
|
---|
237 | production of the list of input files and their use in the commands
|
---|
238 | that
|
---|
239 | .B xargs
|
---|
240 | issues. If other users have access to the system, they can manipulate
|
---|
241 | the filesystem during this time window to force the action of the
|
---|
242 | commands
|
---|
243 | .B xargs
|
---|
244 | runs to apply to files that you didn't intend. For a more detailed
|
---|
245 | discussion of this and related problems, please refer to the
|
---|
246 | ``Security Considerations'' chapter in the findutils Texinfo
|
---|
247 | documentation. The \-execdir option of
|
---|
248 | .B find
|
---|
249 | can often be used as a more secure alternative.
|
---|
250 |
|
---|
251 | When you use the \-I option, each line read from the input is buffered
|
---|
252 | internally. This means that there is an upper limit on the length
|
---|
253 | of input line that
|
---|
254 | .B xargs
|
---|
255 | will accept when used with the \-I option. To work around this
|
---|
256 | limitation, you can use the \-s option to increase the amount of
|
---|
257 | buffer space that
|
---|
258 | .B xargs
|
---|
259 | uses, and you can also use an extra invocation of
|
---|
260 | .B xargs
|
---|
261 | to ensure that very long lines do not occur.
|
---|
262 | For example:
|
---|
263 | .P
|
---|
264 | .B somecommand | xargs \-s 50000 echo | xargs \-I '{}' \-s 100000 rm '{}'
|
---|
265 | .P
|
---|
266 | Here, the first invocation of
|
---|
267 | .B xargs
|
---|
268 | has no input line length limit
|
---|
269 | because it doesn't use the \-i option. The second invocation of
|
---|
270 | .B xargs
|
---|
271 | does have such a limit, but we have ensured that the it never encounters
|
---|
272 | a line which is longer than it can handle. This is not an ideal
|
---|
273 | solution. Instead, the \-i option should not impose a line length
|
---|
274 | limit, which is why this discussion appears in the BUGS section.
|
---|
275 | The problem doesn't occur with the output of
|
---|
276 | .BR find (1)
|
---|
277 | because it emits just one filename per line.
|
---|
278 | .P
|
---|
279 | The best way to report a bug is to use the form at
|
---|
280 | http://savannah.gnu.org/bugs/?group=findutils.
|
---|
281 | The reason for this is that you will then be able to track progress in
|
---|
282 | fixing the problem. Other comments about \fBxargs\fP(1) and about
|
---|
283 | the findutils package in general can be sent to the
|
---|
284 | .I bug\-findutils
|
---|
285 | mailing list. To join the list, send email to
|
---|
286 | .IR bug\-findutils\-request@gnu.org .
|
---|