1XARGS(1)                    General Commands Manual                   XARGS(1)
2
3
4

NAME

6       xargs - build and execute command lines from standard input
7

SYNOPSIS

9       xargs  [-0prtx]  [-E  eof-str] [-e[eof-str]] [--eof[=eof-str]] [--null]
10       [-d delimiter] [--delimiter delimiter]  [-I  replace-str]  [-i[replace-
11       str]]    [--replace[=replace-str]]   [-l[max-lines]]   [-L   max-lines]
12       [--max-lines[=max-lines]] [-n max-args] [--max-args=max-args] [-s  max-
13       chars]  [--max-chars=max-chars]  [-P max-procs] [--max-procs=max-procs]
14       [--interactive]      [--verbose]      [--exit]      [--no-run-if-empty]
15       [--arg-file=file]   [--show-limits]   [--version]   [--help]   [command
16       [initial-arguments]]
17

DESCRIPTION

19       This manual page documents the GNU version of xargs.  xargs reads items
20       from  the  standard  input, delimited by blanks (which can be protected
21       with double or single quotes or a backslash) or newlines, and  executes
22       the  command (default is /bin/echo) one or more times with any initial-
23       arguments followed by items read from standard input.  Blank  lines  on
24       the standard input are ignored.
25
26       Because  Unix  filenames  can contain blanks and newlines, this default
27       behaviour is often problematic; filenames containing blanks and/or new‐
28       lines  are  incorrectly  processed by xargs.  In these situations it is
29       better to use the -0 option, which prevents such problems.   When using
30       this option you will need to ensure that the program which produces the
31       input for xargs also uses a null character as  a  separator.   If  that
32       program is GNU find for example, the -print0 option does this for you.
33
34       If any invocation of the command exits with a status of 255, xargs will
35       stop immediately without reading any further input.  An  error  message
36       is issued on stderr when this happens.
37

OPTIONS

39       --arg-file=file
40       -a file
41              Read items from file instead of standard input.  If you use this
42              option, stdin remains unchanged when commands are  run.   Other‐
43              wise, stdin is redirected from /dev/null.
44
45       --null
46       -0     Input  items  are  terminated  by a null character instead of by
47              whitespace, and the quotes and backslash are not special  (every
48              character is taken literally).  Disables the end of file string,
49              which is treated like any other  argument.   Useful  when  input
50              items  might  contain  white space, quote marks, or backslashes.
51              The GNU find -print0 option produces  input  suitable  for  this
52              mode.
53
54
55       --delimiter=delim
56       -d delim
57              Input  items  are terminated by the specified character.  Quotes
58              and backslash are not special; every character in the  input  is
59              taken  literally.   Disables  the  end-of-file  string, which is
60              treated like any other argument.  This can be used when the  in‐
61              put  consists  of simply newline-separated items, although it is
62              almost always better to design your program to use --null  where
63              this is possible.  The specified delimiter may be a single char‐
64              acter, a C-style character escape such as \n,  or  an  octal  or
65              hexadecimal escape code.  Octal and hexadecimal escape codes are
66              understood as for the printf command.   Multibyte characters are
67              not supported.
68
69
70       -E eof-str
71              Set  the  end  of  file  string  to eof-str.  If the end of file
72              string occurs as a line of input, the rest of the input  is  ig‐
73              nored.   If  neither -E nor -e is used, no end of file string is
74              used.
75
76       --eof[=eof-str]
77       -e[eof-str]
78              This option is a synonym for the -E option.  Use -E instead, be‐
79              cause  it  is POSIX compliant while this option is not.  If eof-
80              str is omitted, there is no end of file string.  If  neither  -E
81              nor -e is used, no end of file string is used.
82
83       --help Print a summary of the options to xargs and exit.
84
85       -I replace-str
86              Replace occurrences of replace-str in the initial-arguments with
87              names read from standard input.  Also, unquoted  blanks  do  not
88              terminate  input  items;  instead  the  separator is the newline
89              character.  Implies -x and -L 1.
90
91       --replace[=replace-str]
92       -i[replace-str]
93              This option is a synonym for  -Ireplace-str  if  replace-str  is
94              specified,  and  for -I{} otherwise.  This option is deprecated;
95              use -I instead.
96
97       -L max-lines
98              Use at most max-lines nonblank input  lines  per  command  line.
99              Trailing blanks cause an input line to be logically continued on
100              the next input line.  Implies -x.
101
102       --max-lines[=max-lines]
103       -l[max-lines]
104              Synonym for the -L option.  Unlike -L, the max-lines argument is
105              optional.   If  max-lines  is not specified, it defaults to one.
106              The -l option is deprecated since the POSIX  standard  specifies
107              -L instead.
108
109       --max-args=max-args
110       -n max-args
111              Use  at  most  max-args  arguments per command line.  Fewer than
112              max-args arguments will be used if the size (see the -s  option)
113              is  exceeded, unless the -x option is given, in which case xargs
114              will exit.
115
116       --interactive
117       -p     Prompt the user about whether to run each command line and  read
118              a  line from the terminal.  Only run the command line if the re‐
119              sponse starts with `y' or `Y'.  Implies -t.
120
121       --no-run-if-empty
122       -r     If the standard input does not contain any nonblanks, do not run
123              the command.  Normally, the command is run once even if there is
124              no input.  This option is a GNU extension.
125
126       --max-chars=max-chars
127       -s max-chars
128              Use at most max-chars characters per command line, including the
129              command  and  initial-arguments and the terminating nulls at the
130              ends of the argument strings.  The largest allowed value is sys‐
131              tem-dependent,  and  is  calculated as the argument length limit
132              for exec, less the size of your environment, less 2048 bytes  of
133              headroom.   If this value is more than 128KiB, 128Kib is used as
134              the default value; otherwise, the default value is the  maximum.
135              1KiB is 1024 bytes.
136
137       --verbose
138       -t     Print  the command line on the standard error output before exe‐
139              cuting it.
140
141       --version
142              Print the version number of xargs and exit.
143
144       --show-limits
145              Display the limits on the command-line length which are  imposed
146              by the operating system, xargs' choice of buffer size and the -s
147              option.  Pipe the input  from  /dev/null  (and  perhaps  specify
148              --no-run-if-empty) if you don't want xargs to do anything.
149
150       --exit
151       -x     Exit if the size (see the -s option) is exceeded.
152
153       --max-procs=max-procs
154       -P max-procs
155              Run  up  to max-procs processes at a time; the default is 1.  If
156              max-procs is 0, xargs will run as many processes as possible  at
157              a  time.   Use the -n option with -P; otherwise chances are that
158              only one exec will be done.
159

EXAMPLES

161       find /tmp -name core -type f -print | xargs /bin/rm -f
162
163       Find files named core in or below the directory /tmp and  delete  them.
164       Note  that  this  will work incorrectly if there are any filenames con‐
165       taining newlines or spaces.
166
167       find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f
168
169       Find files named core in or below the directory /tmp and  delete  them,
170       processing  filenames  in  such a way that file or directory names con‐
171       taining spaces or newlines are correctly handled.
172
173
174       find /tmp -depth -name core -type f -delete
175
176       Find files named core in or below the directory /tmp and  delete  them,
177       but more efficiently than in the previous example (because we avoid the
178       need to use fork(2) and exec(2) to launch rm and we don't need the  ex‐
179       tra xargs process).
180
181
182       cut -d: -f1 < /etc/passwd | sort | xargs echo
183
184       Generates a compact listing of all the users on the system.
185
186
187       xargs sh -c 'emacs "$@" < /dev/tty' emacs
188
189       Launches  the  minimum  number of copies of Emacs needed, one after the
190       other, to edit the files listed on xargs' standard input.  This example
191       achieves the same effect as BSD's -o option, but in a more flexible and
192       portable way.
193
194
195
196

EXIT STATUS

198       xargs exits with the following status:
199       0 if it succeeds
200       123 if any invocation of the command exited with status 1-125
201       124 if the command exited with status 255
202       125 if the command is killed by a signal
203       126 if the command cannot be run
204       127 if the command is not found
205       1 if some other error occurred.
206
207       Exit codes greater than 128 are used by the shell to  indicate  that  a
208       program died due to a fatal signal.
209

STANDARDS CONFORMANCE

211       As of GNU xargs version 4.2.9, the default behaviour of xargs is not to
212       have a logical end-of-file marker.  POSIX (IEEE Std 1003.1,  2004  Edi‐
213       tion) allows this.
214
215       The -l and -i options appear in the 1997 version of the POSIX standard,
216       but do not appear in the 2004 version of the standard.   Therefore  you
217       should use -L and -I instead, respectively.
218
219       The  POSIX  standard allows implementations to have a limit on the size
220       of arguments to the exec functions.  This limit could be as low as 4096
221       bytes  including the size of the environment.  For scripts to be porta‐
222       ble, they must not rely on a larger value.  However, I know of  no  im‐
223       plementation  whose  actual limit is that small.  The --show-limits op‐
224       tion can be used to discover the actual limits in force on the  current
225       system.
226
227
228

SEE ALSO

230       find(1), locate(1), locatedb(5), updatedb(1), fork(2), execvp(3), Find‐
231       ing Files (on-line in Info, or printed)
232

BUGS

234       The -L option is incompatible with the -I option,  but  perhaps  should
235       not be.
236
237       It  is not possible for xargs to be used securely, since there will al‐
238       ways be a time gap between the production of the list  of  input  files
239       and  their  use in the commands that xargs issues.  If other users have
240       access to the system, they can manipulate the  filesystem  during  this
241       time  window to force the action of the commands xargs runs to apply to
242       files that you didn't intend.  For a more detailed discussion  of  this
243       and  related  problems, please refer to the ``Security Considerations''
244       chapter in the findutils Texinfo documentation.  The -execdir option of
245       find can often be used as a more secure alternative.
246
247       When  you  use the -I option, each line read from the input is buffered
248       internally.   This means that there is an upper limit on the length  of
249       input  line  that  xargs  will accept when used with the -I option.  To
250       work around this limitation, you can use the -s option to increase  the
251       amount  of  buffer space that xargs uses, and you can also use an extra
252       invocation of xargs to ensure that very long lines do not  occur.   For
253       example:
254
255       somecommand | xargs -s 50000 echo | xargs -I '{}' -s 100000 rm '{}'
256
257       Here,  the first invocation of xargs has no input line length limit be‐
258       cause it doesn't use the -i option.  The  second  invocation  of  xargs
259       does  have  such a limit, but we have ensured that the it never encoun‐
260       ters a line which is longer than it can handle.   This is not an  ideal
261       solution.   Instead, the -i option should not impose a line length lim‐
262       it, which is why this discussion appears  in  the  BUGS  section.   The
263       problem  doesn't occur with the output of find(1) because it emits just
264       one filename per line.
265
266       The best way to report a bug  is  to  use  the  form  at  http://savan
267       nah.gnu.org/bugs/?group=findutils.   The  reason  for  this is that you
268       will then be able to track progress in fixing the problem.   Other com‐
269       ments  about xargs(1) and about the findutils package in general can be
270       sent to the bug-findutils mailing list.  To join the list,  send  email
271       to bug-findutils-request@gnu.org.
272
273
274
275                                                                      XARGS(1)
Impressum