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 [ini‐
16       tial-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
30       using  this  option you will need to ensure that the program which pro‐
31       duces the input for xargs also uses a null character  as  a  separator.
32       If that program is GNU find for example, the `-print0' option does this
33       for you.
34
35       If any invocation of the command exits with a status of 255, xargs will
36       stop  immediately  without reading any further input.  An error message
37       is issued on stderr when this happens.
38
39   OPTIONS
40       --arg-file=file, -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
46       --null, -0
47              Input items are terminated by a null  character  instead  of  by
48              whitespace,  and the quotes and backslash are not special (every
49              character is taken literally).  Disables the end of file string,
50              which  is  treated  like  any other argument.  Useful when input
51              items might contain white space, quote  marks,  or  backslashes.
52              The  GNU  find  -print0  option produces input suitable for this
53              mode.
54
55       --delimiter=delim, -d delim
56              Input items are terminated by the specified  character.   Quotes
57              and  backslash  are not special; every character in the input is
58              taken literally.  Disables  the  end-of-file  string,  which  is
59              treated  like  any  other  argument.   This can be used when the
60              input consists of simply newline-separated items, although it is
61              almost  always  better  to  design  your program to use `--null'
62              where this is possible.  The specified delimiter may be a single
63              character, a C-style character escape such as \n, or an octal or
64              hexadecimal escape code.  Octal and hexadecimal escape codes are
65              understood as for the printf command.   Multibyte characters are
66              not supported.
67
68
69       -Eeof-str
70              Set the end of file string to  eof-str.   If  the  end  of  file
71              string  occurs  as  a  line  of  input, the rest of the input is
72              ignored.  If neither -E nor -e is used, no end of file string is
73              used.
74
75       --eof[=eof-str], -e[eof-str]
76              This option is a synonym for the `-E' option.  Use `-E' instead,
77              because it is POSIX compliant while this option is not.  If eof-
78              str  is  omitted, there is no end of file string.  If neither -E
79              nor -e is used, no end of file string is used.
80
81       --help Print a summary of the options to xargs and exit.
82
83       -I replace-str
84              Replace occurrences of replace-str in the initial-arguments with
85              names  read  from  standard input.  Also, unquoted blanks do not
86              terminate input items; instead  the  separator  is  the  newline
87              character.  Implies -x and -L 1.
88
89       --replace[=replace-str], -i[replace-str]
90              This  option  is  a  synonym for -Ireplace-str if replace-str is
91              specified, and for -I{} otherwise.  This option  is  deprecated;
92              use -I instead.
93
94       -L max-lines
95              Use  at  most  max-lines  nonblank input lines per command line.
96              Trailing blanks cause an input line to be logically continued on
97              the next input line.  Implies -x.
98
99       --max-lines[=max-lines], -l[max-lines]
100              Synonym for the -L option.  Unlike -L, the max-lines argument is
101              optional.  If max-args is not specified,  it  defaults  to  one.
102              The  -l  option is deprecated since the POSIX standard specifies
103              -L instead.
104
105       --max-args=max-args, -n max-args
106              Use at most max-args arguments per  command  line.   Fewer  than
107              max-args  arguments will be used if the size (see the -s option)
108              is exceeded, unless the -x option is given, in which case  xargs
109              will exit.
110
111       --interactive, -p
112              Prompt  the user about whether to run each command line and read
113              a line from the terminal.  Only run  the  command  line  if  the
114              response starts with `y' or `Y'.  Implies -t.
115
116       --no-run-if-empty, -r
117              If the standard input does not contain any nonblanks, do not run
118              the command.  Normally, the command is run once even if there is
119              no input.  This option is a GNU extension.
120
121       --max-chars=max-chars, -s max-chars
122              Use at most max-chars characters per command line, including the
123              command and initial-arguments and the terminating nulls  at  the
124              ends of the argument strings.  The default is 131072 characters,
125              not including the size of the environment variables  (which  are
126              provided  for separately so that it doesn't matter if your envi‐
127              ronment variables take up more than 131072 bytes).  The  operat‐
128              ing  system  places  limits  on the values that you can usefully
129              specify, and if you exceed these a warning  message  is  printed
130              and  the  value actually used is set to the appropriate upper or
131              lower limit.
132
133       --verbose, -t
134              Print the command line on the standard error output before  exe‐
135              cuting it.
136
137       --version
138              Print the version number of xargs and exit.
139
140       --show-limits
141              Display  the limits on the command-line length which are imposed
142              by the operating system, xargs' choice of buffer size and the -s
143              option.   Pipe  the  input  from  /dev/null (and perhaps specify
144              --no-run-if-empty) if you don't want xargs to do anything.
145
146       --exit, -x
147              Exit if the size (see the -s option) is exceeded.
148
149       --max-procs=max-procs, -P max-procs
150              Run up to max-procs processes at a time; the default is  1.   If
151              max-procs  is 0, xargs will run as many processes as possible at
152              a time.  Use the -n option with -P; otherwise chances  are  that
153              only one exec will be done.
154

EXAMPLES

156       find /tmp -name core -type f -print | xargs /bin/rm -f
157
158       Find  files  named core in or below the directory /tmp and delete them.
159       Note that this will work incorrectly if there are  any  filenames  con‐
160       taining newlines or spaces.
161
162       find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f
163
164       Find  files  named core in or below the directory /tmp and delete them,
165       processing filenames in such a way that file or  directory  names  con‐
166       taining spaces or newlines are correctly handled.
167
168       cut -d: -f1 < /etc/passwd | sort | xargs echo
169
170       Generates a compact listing of all the users on the system.
171

EXIT STATUS

173       xargs 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.
181
182       Exit  codes  greater  than 128 are used by the shell to indicate that a
183       program died due to a fatal signal.
184

STANDARDS CONFORMANCE

186       As of GNU xargs version 4.2.9, the default behaviour of xargs is not to
187       have  a  logical end-of-file marker.  POSIX (IEEE Std 1003.1, 2004 Edi‐
188       tion) allows this.
189
190       The -l and -i options appear in the 1997 version of the POSIX standard,
191       but  do  not appear in the 2004 version of the standard.  Therefore you
192       should use -L and -I instead, respectively.
193
194

SEE ALSO

196       find(1), locate(1), locatedb(5), updatedb(1), Finding Files (on-line in
197       Info, or printed)
198

BUGS

200       The  -L  option  is incompatible with the -I option, but perhaps should
201       not be.
202
203       It is not possible for xargs to be  used  securely,  since  there  will
204       always  be a time gap between the production of the list of input files
205       and their use in the commands that xargs issues.  If other  users  have
206       access  to  the  system, they can manipulate the filesystem during this
207       time window to force the action of the commands xargs runs to apply  to
208       files  that  you didn't intend.  For a more detailed discussion of this
209       and related problems, please refer to the  ``Security  Considerations''
210       chapter in the findutils Texinfo documentation.  The -execdir option of
211       find can often be used as a more secure alternative.
212
213       When you use the -I option, each line read from the input  is  buffered
214       internally.    This means that there is an upper limit on the length of
215       input line that xargs will accept when used with  the  -I  option.   To
216       work  around this limitation, you can use the -s option to increase the
217       amount of buffer space that xargs uses, and you can also use  an  extra
218       invocation  of  xargs to ensure that very long lines do not occur.  For
219       example:
220
221       somecommand | xargs -s 50000 echo | xargs -I '{}' -s 100000 rm '{}'
222
223       Here, the first invocation of xargs has  no  input  line  length  limit
224       because  it  doesn't use the -i option.  The second invocation of xargs
225       does have such a limit, but we have ensured that the it  never  encoun‐
226       ters  a line which is longer than it can handle.   This is not an ideal
227       solution.  Instead, the -i option  should  not  impose  a  line  length
228       limit,  which  is why this discussion appears in the BUGS section.  The
229       problem doesn't occur with the output of find(1) because it emits  just
230       one filename per line.
231
232       The  best  way  to  report  a  bug  is to use the form at http://savan
233       nah.gnu.org/bugs/?group=findutils.  The reason for  this  is  that  you
234       will then be able to track progress in fixing the problem.   Other com‐
235       ments about xargs(1) and about the findutils package in general can  be
236       sent  to  the bug-findutils mailing list.  To join the list, send email
237       to bug-findutils-request@gnu.org.
238
239
240
241                                                                      XARGS(1)
Impressum