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 [options] [command [initial-arguments]]
10

DESCRIPTION

12       This manual page documents the GNU version of xargs.  xargs reads items
13       from the standard input, delimited by blanks (which  can  be  protected
14       with  double or single quotes or a backslash) or newlines, and executes
15       the command (default is /bin/echo) one or more times with any  initial-
16       arguments  followed  by items read from standard input.  Blank lines on
17       the standard input are ignored.
18
19       The command line for command is built up until it reaches a  system-de‐
20       fined  limit  (unless  the  -n and -L options are used).  The specified
21       command will be invoked as many times as necessary to use up  the  list
22       of  input  items.   In general, there will be many fewer invocations of
23       command than there were items in the input.  This  will  normally  have
24       significant  performance  benefits.  Some commands can usefully be exe‐
25       cuted in parallel too; see the -P option.
26
27       Because Unix filenames can contain blanks and  newlines,  this  default
28       behaviour is often problematic; filenames containing blanks and/or new‐
29       lines are incorrectly processed by xargs.  In these  situations  it  is
30       better to use the -0 option, which prevents such problems.   When using
31       this option you will need to ensure that the program which produces the
32       input  for  xargs  also  uses a null character as a separator.  If that
33       program is GNU find for example, the -print0 option does this 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

OPTIONS

40       -0, --null
41              Input items are terminated by a null  character  instead  of  by
42              whitespace,  and the quotes and backslash are not special (every
43              character is taken literally).  Disables the end of file string,
44              which  is  treated  like  any other argument.  Useful when input
45              items might contain white space, quote  marks,  or  backslashes.
46              The  GNU  find  -print0  option produces input suitable for this
47              mode.
48
49
50       -a file, --arg-file=file
51              Read items from file instead of standard input.  If you use this
52              option,  stdin  remains unchanged when commands are run.  Other‐
53              wise, stdin is redirected from /dev/null.
54
55
56       --delimiter=delim, -d delim
57              Input items are terminated  by  the  specified  character.   The
58              specified delimiter may be a single character, a C-style charac‐
59              ter escape such as \n, or an octal or hexadecimal  escape  code.
60              Octal  and  hexadecimal  escape  codes are understood as for the
61              printf command.   Multibyte characters are not supported.   When
62              processing  the input, quotes and backslash are not special; ev‐
63              ery character in the input is taken literally.   The  -d  option
64              disables any end-of-file string, which is treated like any other
65              argument.  You can use this option when the  input  consists  of
66              simply  newline-separated  items,  although  it is almost always
67              better to design your program to use --null where this is possi‐
68              ble.
69
70
71       -E eof-str
72              Set  the  end  of  file  string  to eof-str.  If the end of file
73              string occurs as a line of input, the rest of the input  is  ig‐
74              nored.   If  neither -E nor -e is used, no end of file string is
75              used.
76
77       -e[eof-str], --eof[=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       -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       -i[replace-str], --replace[=replace-str]
90              This option is a synonym for  -Ireplace-str  if  replace-str  is
91              specified.   If  the replace-str argument is missing, the effect
92              is the same as -I{}.  This option is deprecated; 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       -l[max-lines], --max-lines[=max-lines]
100              Synonym for the -L option.  Unlike -L, the max-lines argument is
101              optional.   If  max-lines  is not specified, it defaults to one.
102              The -l option is deprecated since the POSIX  standard  specifies
103              -L instead.
104
105       -n max-args, --max-args=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       -P max-procs, --max-procs=max-procs
112              Run up to max-procs processes at a time; the default is  1.   If
113              max-procs  is 0, xargs will run as many processes as possible at
114              a time.  Use the -n option or the -L option with  -P;  otherwise
115              chances  are  that  only  one exec will be done.  While xargs is
116              running, you can send its process a SIGUSR1 signal  to  increase
117              the  number  of  commands to run simultaneously, or a SIGUSR2 to
118              decrease the number.  You cannot increase it above an  implemen‐
119              tation-defined  limit  (which is shown with --show-limits).  You
120              cannot decrease it below 1.  xargs  never  terminates  its  com‐
121              mands; when asked to decrease, it merely waits for more than one
122              existing command to terminate before starting another.
123
124              Please note that it is up to the called  processes  to  properly
125              manage  parallel  access  to  shared resources.  For example, if
126              more than one of them tries to print to stdout, the output  will
127              be produced in an indeterminate order (and very likely mixed up)
128              unless the processes collaborate in some way  to  prevent  this.
129              Using  some  kind  of  locking scheme is one way to prevent such
130              problems.  In general, using a locking scheme will  help  ensure
131              correct  output  but  reduce  performance.  If you don't want to
132              tolerate the performance difference,  simply  arrange  for  each
133              process to produce a separate output file (or otherwise use sep‐
134              arate resources).
135
136       -o, --open-tty
137              Reopen stdin as /dev/tty in the child process  before  executing
138              the  command.  This is useful if you want xargs to run an inter‐
139              active application.
140
141       -p, --interactive
142              Prompt the user about whether to run each command line and  read
143              a  line from the terminal.  Only run the command line if the re‐
144              sponse starts with `y' or `Y'.  Implies -t.
145
146       --process-slot-var=name
147              Set the environment variable name to a unique value in each run‐
148              ning  child process.  Values are reused once child processes ex‐
149              it.  This can be used in a rudimentary load distribution scheme,
150              for example.
151
152       -r, --no-run-if-empty
153              If the standard input does not contain any nonblanks, do not run
154              the command.  Normally, the command is run once even if there is
155              no input.  This option is a GNU extension.
156
157       -s max-chars, --max-chars=max-chars
158              Use at most max-chars characters per command line, including the
159              command and initial-arguments and the terminating nulls  at  the
160              ends of the argument strings.  The largest allowed value is sys‐
161              tem-dependent, and is calculated as the  argument  length  limit
162              for  exec, less the size of your environment, less 2048 bytes of
163              headroom.  If this value is more than 128KiB, 128Kib is used  as
164              the  default value; otherwise, the default value is the maximum.
165              1KiB is 1024 bytes.  xargs automatically adapts to tighter  con‐
166              straints.
167
168       --show-limits
169              Display  the limits on the command-line length which are imposed
170              by the operating system, xargs' choice of buffer size and the -s
171              option.   Pipe  the  input  from  /dev/null (and perhaps specify
172              --no-run-if-empty) if you don't want xargs to do anything.
173
174       -t, --verbose
175              Print the command line on the standard error output before  exe‐
176              cuting it.
177
178       -x, --exit
179              Exit if the size (see the -s option) is exceeded.
180
181       --help Print a summary of the options to xargs and exit.
182
183       --version
184              Print the version number of xargs and exit.
185
186       The  options  --max-lines  (-L,  -l), --replace (-I, -i) and --max-args
187       (-n) are mutually exclusive. If some of them are specified at the  same
188       time,  then  xargs  will generally use the option specified last on the
189       command line, i.e., it will reset the value  of  the  offending  option
190       (given  before) to its default value.  Additionally, xargs will issue a
191       warning diagnostic on stderr.  The exception to this rule is  that  the
192       special  max-args value 1 ('-n1') is ignored after the --replace option
193       and its aliases -I and -i, because it would not actually conflict.
194
195

EXAMPLES

197       find /tmp -name core -type f -print | xargs /bin/rm -f
198
199       Find files named core in or below the directory /tmp and  delete  them.
200       Note  that  this  will work incorrectly if there are any filenames con‐
201       taining newlines or spaces.
202
203       find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f
204
205       Find files named core in or below the directory /tmp and  delete  them,
206       processing  filenames  in  such a way that file or directory names con‐
207       taining spaces or newlines are correctly handled.
208
209
210       find /tmp -depth -name core -type f -delete
211
212       Find files named core in or below the directory /tmp and  delete  them,
213       but more efficiently than in the previous example (because we avoid the
214       need to use fork(2) and exec(2) to launch rm and we don't need the  ex‐
215       tra xargs process).
216
217
218       cut -d: -f1 < /etc/passwd | sort | xargs echo
219
220       Generates a compact listing of all the users on the system.
221

EXIT STATUS

223       xargs exits with the following status:
224
225              0      if it succeeds
226
227              123    if any invocation of the command exited with status 1-125
228
229              124    if the command exited with status 255
230
231              125    if the command is killed by a signal
232
233              126    if the command cannot be run
234
235              127    if the command is not found
236
237              1      if some other error occurred.
238
239
240       Exit  codes  greater  than 128 are used by the shell to indicate that a
241       program died due to a fatal signal.
242

STANDARDS CONFORMANCE

244       As of GNU xargs version 4.2.9, the default behaviour of xargs is not to
245       have  a  logical end-of-file marker.  POSIX (IEEE Std 1003.1, 2004 Edi‐
246       tion) allows this.
247
248       The -l and -i options appear in the 1997 version of the POSIX standard,
249       but  do  not appear in the 2004 version of the standard.  Therefore you
250       should use -L and -I instead, respectively.
251
252       The -o option is an extension to the POSIX standard for better compati‐
253       bility with BSD.
254
255       The  POSIX  standard allows implementations to have a limit on the size
256       of arguments to the exec functions.  This limit could be as low as 4096
257       bytes  including the size of the environment.  For scripts to be porta‐
258       ble, they must not rely on a larger value.  However, I know of  no  im‐
259       plementation  whose  actual limit is that small.  The --show-limits op‐
260       tion can be used to discover the actual limits in force on the  current
261       system.
262

BUGS

264       It  is not possible for xargs to be used securely, since there will al‐
265       ways be a time gap between the production of the list  of  input  files
266       and  their  use in the commands that xargs issues.  If other users have
267       access to the system, they can manipulate the  filesystem  during  this
268       time  window to force the action of the commands xargs runs to apply to
269       files that you didn't intend.  For a more detailed discussion  of  this
270       and  related  problems, please refer to the ``Security Considerations''
271       chapter in the findutils Texinfo documentation.  The -execdir option of
272       find can often be used as a more secure alternative.
273
274       When  you  use the -I option, each line read from the input is buffered
275       internally.   This means that there is an upper limit on the length  of
276       input  line  that  xargs  will accept when used with the -I option.  To
277       work around this limitation, you can use the -s option to increase  the
278       amount  of  buffer space that xargs uses, and you can also use an extra
279       invocation of xargs to ensure that very long lines do not  occur.   For
280       example:
281
282       somecommand | xargs -s 50000 echo | xargs -I '{}' -s 100000 rm '{}'
283
284       Here,  the first invocation of xargs has no input line length limit be‐
285       cause it doesn't use the -i option.  The  second  invocation  of  xargs
286       does  have such a limit, but we have ensured that it never encounters a
287       line which is longer than it can handle.   This is not an  ideal  solu‐
288       tion.   Instead,  the  -i option should not impose a line length limit,
289       which is why this discussion appears in the BUGS section.  The  problem
290       doesn't  occur  with  the  output  of find(1) because it emits just one
291       filename per line.
292

REPORTING BUGS

294       GNU   findutils   online   help:   <https://www.gnu.org/software/findu
295       tils/#get-help>
296       Report any translation bugs to <https://translationproject.org/team/>
297
298       Report any other issue via the form at the GNU Savannah bug tracker:
299              <https://savannah.gnu.org/bugs/?group=findutils>
300       General  topics  about  the  GNU findutils package are discussed at the
301       bug-findutils mailing list:
302              <https://lists.gnu.org/mailman/listinfo/bug-findutils>
303
305       Copyright © 1990-2021 Free Software Foundation, Inc.   License  GPLv3+:
306       GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
307       This  is  free  software:  you  are free to change and redistribute it.
308       There is NO WARRANTY, to the extent permitted by law.
309

SEE ALSO

311       find(1), kill(1), locate(1), updatedb(1),  fork(2),  execvp(3),  locat‐
312       edb(5), signal(7)
313
314       Full documentation <https://www.gnu.org/software/findutils/xargs>
315       or available locally via: info xargs
316
317
318
319                                                                      XARGS(1)
Impressum