XARGS(1)
โจ NAME โจ
xargs โ build and execute command lines from standard input ๐
๐ธ SYNOPSIS ๐ธ
xargs [option ...] [command] [initial-argument ...]
๐ DESCRIPTION ๐
Okay so bestie, this manual page documents the GNU version of xargs. xargs reads items from the standard input, delimited by blanks (which can be protected with double or single quotes or a backslash) or newlines, and executes the command (default is echo) one or more times with any initial-arguments followed by items read from standard input. Blank lines on the standard input are ignored. Periodt. โจ
The command line for command is built up until it reaches a system-defined limit (unless the -n and -L options are used). The specified command will be invoked as many times as necessary to use up the list of input items. In general, there will be many fewer invocations of command than there were items in the input. This will normally have significant performance benefits. Some commands can usefully be executed in parallel too; see the -P option. ๐
Because Unix filenames can contain blanks and newlines, this default behaviour is often problematic; filenames containing blanks and/or newlines are incorrectly processed by xargs. In these situations it is better to use the -0 option, which prevents such problems. When using this option you will need to ensure that the program which produces the input for xargs also uses a null character as a separator. If that program is GNU find for example, the -print0 option does this for you. ๐ซถ
If any invocation of the command exits with a status of 255, xargs will stop immediately without reading any further input. An error message is issued on standard error when this happens. ๐
๐ OPTIONS ๐
-0,--nullโ Input items are terminated by a null character instead of by whitespace, and the quotes and backslash are not special (every character is taken literally). Disables the end-of-file string, which is treated like any other argument. Useful when input items might contain white space, quote marks, or backslashes. The GNUfind(and from POSIX Issue 8, IEEE Std 1003.1, 2024)-print0option produces input suitable for this mode. ๐-afile,--arg-file=fileโ Read items from file instead of standard input. If you use this option, standard input remains unchanged when commands are run. Otherwise, standard input is redirected from/dev/null. ๐ธ--delimiter=delim,-ddelim โ Input items are terminated by the specified character. The specified delimiter may be a single character, a C-style character escape such as\n, or an octal or hexadecimal escape code. Octal and hexadecimal escape codes are understood as for theprintfcommand. Multibyte characters are not supported. When processing the input, quotes and backslash are not special; every character in the input is taken literally. The-doption disables any end-of-file string, which is treated like any other argument. You can use this option when the input consists of simply newline-separated items, although it is almost always better to design your program to use--nullwhere this is possible. โจ-Eeof-str โ Set the end-of-file string to eof-str. If the end-of-file string occurs as a line of input, the rest of the input is ignored. If neither-Enor-eis used, no end-of-file string is used. Other implementations ofxargsmay have a default logical end-of-file string, so if you want to portably ensure that no logical end-of-file string is in use, use-E ""to disable the logical end-of-file string. See also STANDARDS CONFORMANCE. ๐ฆ-e[eof-str],--eof[=eof-str]โ This option is a synonym for the-Eoption. Use-Einstead, because it is still POSIX-compliant whereas the-eoption was removed from the POSIX standard (IEEE Std 1003.1, 2004 Edition). ๐-Ireplace-str โ Replace occurrences of replace-str in the initial-arguments with names read from standard input. Also, unquoted blanks do not terminate input items; instead the separator is the newline character. Implies-xand โ-L 1โ. ๐-i[replace-str],--replace[=replace-str]โ This option is a synonym for-Ireplace-strif replace-str is specified. If the replace-str argument is missing, the effect is the same as โ-I{}โ. The-ioption was removed from the POSIX standard (IEEE Std 1003.1, 2004 Edition). Use-Iinstead. ๐-Lmax-lines โ Use at most max-lines nonblank input lines per command line. Trailing blanks cause an input line to be logically continued on the next input line. Implies-x. ๐-l[max-lines],--max-lines[=max-lines]โ Synonym for the-Loption. Unlike-L, the max-lines argument is optional. If max-lines is not specified, it defaults to one. The-loption is deprecated since the POSIX standard specifies-Linstead. ๐-nmax-args,--max-args=max-argsโ Use at most max-args arguments per command line. Fewer than max-args arguments will be used if the size (see the-soption) is exceeded, unless the-xoption is given, in which casexargswill exit. ๐ฅ-Pmax-procs,--max-procs=max-procsโ Run up to max-procs processes at a time; the default is1. If max-procs is0,xargswill run as many processes as possible at a time. Use the-noption or the-Loption with-P; otherwise chances are that only one exec will be done. Whilexargsis running, you can send its process aSIGUSR1signal to increase the number of commands to run simultaneously, or aSIGUSR2to decrease the number. You cannot increase it above an implementation-defined limit (which is shown with--show-limits). You cannot decrease it below1.xargsnever terminates its commands; when asked to decrease, it merely waits for more than one existing command to terminate before starting another.xargsalways waits for all child processes to exit before exiting itself (but seeBUGS).
If you do not use the -P option, xargs will not handle the SIGUSR1 and SIGUSR2 signals, meaning that they will terminate the program (unless they were blocked in the parent process before xargs was started).
Please note that it is up to the called processes to properly manage parallel access to shared resources. For example, if more than one of them tries to print to standard output, the output will be produced in an indeterminate order (and very likely mixed up) unless the processes collaborate in some way to prevent this. Using some kind of locking scheme is one way to prevent such problems. In general, using a locking scheme will help ensure correct output but reduce performance. If you don't want to tolerate the performance difference, simply arrange for each process to produce a separate output file (or otherwise use separate resources). ๐
-o,--open-ttyโ Reopen standard input as/dev/ttyin the child process before executing the command. This is useful if you wantxargsto run an interactive application. ๐-p,--interactiveโ Prompt the user about whether to run each command line and read a line from the terminal. Only run the command line if the response starts withyorY. Implies-t. ๐ซถ--process-slot-var=nameโ Set the environment variable name to a unique value in each running child process. Values are reused once child processes exit. This can be used in a rudimentary load distribution scheme, for example. โจ-r,--no-run-if-emptyโ If the standard input does not contain any nonblanks, do not run the command. Normally, the command is run once even if there is no input. ๐-smax-chars,--max-chars=max-charsโ Use at most max-chars characters per command line, including the command and initial-arguments and the terminating nulls at the ends of the argument strings. The largest allowed value is system-dependent, and is calculated as the argument length limit forexec, less the size of your environment, less2048bytes of headroom. If this value is more than128 KiB,128 KiBis used as the default value; otherwise, the default value is the maximum.1 KiBis1024bytes.xargsautomatically adapts to tighter constraints. ๐ธ--show-limitsโ Display the limits on the command-line length which are imposed by the operating system,xargs' choice of buffer size and the-soption. Pipe the input from/dev/null(and perhaps specify--no-run-if-empty) if you don't wantxargsto do anything. ๐-t,--verboseโ Print the command line on the standard error output before executing it. ๐ฅ-x,--exitโ Exit if the size (see the-soption) is exceeded. ๐--โ Delimit the option list. Later arguments, if any, are treated as operands even if they begin with โ-โ. For example, โxargs -- --helpโ runs the command--help(found inPATH) instead of printing the usage text, and โxargs -- --mycommandโ runs the command--mycommandinstead of rejecting this as unrecognized option. ๐ฆ--helpโ Print a summary of the options toxargsand exit. ๐--versionโ Print the version number ofxargsand exit. ๐
The options --max-lines (-L, -l), --replace (-I, -i), and --max-args (-n) are mutually exclusive. If some of them are specified at the same time, then xargs will generally use the option specified last on the command line, i.e., it will reset the value of the offending option (given before) to its default value. Additionally, xargs will issue a warning diagnostic on standard error. The exception to this rule is that the special max-args value โ1โ (as in โ-n1โ) is ignored after the --replace option and its aliases -I and -i, because it would not actually conflict. ๐ซถ
๐ EXAMPLES ๐
okay bestie, these are the classic ones, and honestly? they're giving "rite of passage." let's go ๐
find /tmp -name core -type f -print | xargs /bin/rm -f
so this finds files named core in or below the directory /tmp and deletes them. BUT โ and this is important, don't skip this โ it will work incorrectly if any of the filenames contain newlines or spaces. like, that's not a vibe, that's a bug waiting to happen ๐ซ
find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f
same goal, finds files named core in or below /tmp and deletes them, but this time it processes the filenames in a way that handles file or directory names containing spaces or newlines correctly. this is the one. this is the upgrade. slay ๐
find /tmp -depth -name core -type f -delete
finds files named core in or below /tmp and deletes them, but more efficiently than the previous example โ because we avoid needing to use fork(2) and exec(2) to launch rm, and we also don't need the extra xargs process. efficiency is literally main character energy โจ
cut -d: -f1 < /etc/passwd | sort | xargs echo
generates a compact listing of all the users on the system. cute, useful, iconic ๐
๐ EXIT STATUS ๐
xargs exits with the following status:
0โ if it succeeds (and any commands run byxargs, if there were any, exited normally with exit status0).123โ if any invocation of the command exited with status other than0or255(though see below).124โ if the command exited with status255.125โ if the command is killed by a signal.126โ if the command cannot be run.127โ if the command is not found.1โ if some other error occurred.
it is possible that future versions of xargs may exit with a status in the range 1โ125 when the command it launched fails in some specific way not listed above. nevertheless, xargs will comply with POSIX. the STANDARDS CONFORMANCE section explains the POSIX rules about the exit status of xargs. ๐ฎ
the commands run by xargs are run directly (with execvp(2)) rather than being invoked via the shell. the shell's (128 + signal) convention for reporting that a process had been killed by a signal is not used by xargs. no cap ๐ซ
๐ STANDARDS CONFORMANCE ๐
this section describes the relationship between GNU xargs and the standards with which it complies. some portability considerations are mentioned. buckle up bestie, it's lore time ๐
โจ OPTIONS โจ
options specified in IEEE Std 1003.1, 2024 are -E, -I, -L, -n, -p, -r, -s, -t, -x and -0.
-Eโ since findutils 4.2.9 (2004), GNUxargshas had no default logical end-of-file string. this may not be true of other implementations, so you should use-E ""to be certain. trust nobody, verify everything ๐ง-eโ removed from POSIX in IEEE Std 1003.1, 2004. GNUxargsstill supports this, but you should use-Einstead.-iโ removed from POSIX in IEEE Std 1003.1, 2004. GNUxargsstill supports this but you should use-Iinstead.-lโ removed from POSIX in IEEE Std 1003.1, 2004. GNUxargsstill supports this but you should use-Linstead.-oโ an extension to the POSIX standard for better compatibility with BSD. not in POSIX.-pโ a GNU extension since before 1994. added to POSIX in IEEE Std 1003.1, 2004.-rโ a GNU extension since before 1994. added to POSIX in IEEE Std 1003.1, 2024.-0โ a GNU extension since before 1994. added to POSIX in IEEE Std 1003.1, 2024.
๐ฆ EXEC SYSTEM CALL LIMITS ๐ฆ
the POSIX standard allows implementations to have a limit on the size of arguments to the exec functions. this limit could be as low as 4096 bytes including the size of the environment. for scripts to be portable, they must not rely on a larger value. however, the author knows of no implementation whose actual limit is that small. the --show-limits option can be used to discover the actual limits in force on the current system. knowledge is power, bestie ๐ช
๐ธ POSIX EXIT STATUS REQUIREMENTS ๐ธ
the POSIX standard specifies that certain kinds of problem must result in particular xargs return values. here's how those requirements relate to the values listed in the EXIT STATUS section ๐
- utility not found โ POSIX exit status:
127; GNUxargsbehavior: exit status127, details:execvp(2)failed with errno valueENOENT. - utility could not be invoked โ POSIX exit status:
126; GNUxargsbehavior: exit status126, details:execvp(2)failed with any other error. - any other non-success case โ POSIX exit status:
1โ125; GNUxargsbehavior:- exit status
125โ utility killed by a fatal signal. - exit status
124โ utility exited with status255. - exit status
123โ utility exited with a status other than0or255. - exit status
2โ122โ may be used in the future. - exit status
1โ any other kind of error (such as a usage error).
- exit status
- successful completion โ POSIX exit status:
0; GNUxargsbehavior: exit status0.
๐ CONFORMANCE BUGS ๐
- Introduced:
4.5.10(2011) - Fixed:
4.10.0(2024) - Description:
SIGUSR1should be a fatal signal by default, butSIGUSR1would not killxargseven if the-Poption was not in use.
๐ HISTORY ๐
the xargs program was invented by Herb Gellis at Bell Labs. see the Texinfo manual for findutils, chapter "Finding Files", for more information. shoutout to the inventor, we love a pioneer ๐ซถ
๐ญ BUGS ๐ญ
๐ SECURITY ๐
it is not possible forxargsto be used securely, since there will always be a time gap between the production of the list of input files and their use in the commands thatxargsissues. if other users have access to the system, they can manipulate the filesystem during this time window to force the action of the commandsxargsruns to apply to files that you didn't intend.
for a more detailed discussion of this and related problems, please refer to the "Security Considerations" chapter in the findutils Texinfo documentation. the -execdir option of find can often be used as a more secure alternative. stay safe out there ๐ก๏ธ
๐ IMPLEMENTATION LIMITS ๐
when you use the -I option, each line read from the input is buffered internally. this means that there is an upper limit on the length of input line that xargs will accept when used with the -I option. to work around this limitation, you can use the -s option to increase the amount of buffer space that xargs uses, and you can also use an extra invocation of xargs to ensure that very long lines do not occur. for example:
somecommand | xargs -s 50000 echo | xargs -I "{}" -s 100000 rm "{}"
here, the first invocation of xargs has no input line length limit because it doesn't use the -i option. the second invocation of xargs does have such a limit, but we have ensured that it never encounters a line which is longer than it can handle. this is not an ideal solution. instead, the -i option should not impose a line length limit, which is why this discussion appears in the BUGS section. the problem doesn't occur with the output of find(1) because it emits just one filename per line. one filename per line = one happy pipeline ๐
๐ซถ REPORTING BUGS ๐ซถ
GNU findutils online help: <https://www.gnu.org/software/findutils/#get-help>
report any translation bugs to <https://translationproject.org/team/>
report any other issue via the form at the GNU Savannah bug tracker: <https://savannah.gnu.org/bugs/?group=findutils>
general topics about the GNU findutils package are discussed at the bug-findutils mailing list: <https://lists.gnu.org/mailman/listinfo/bug-findutils>
found a bug? tell the people! they're literally so nice about it ๐
๐ COPYRIGHT ๐
copyright ยฉ 1990โ2026 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
this is free software: you are free to change and redistribute it. there is NO WARRANTY, to the extent permitted by law.
๐ SEE ALSO ๐
full documentation <https://www.gnu.org/software/findutils/xargs> or available locally via: info xargs
and that's the whole page, bestie ๐ฆ this was findutils, dated 2024-06-03, and the page is XARGS(1) โ go forth and pipe responsibly, you absolute icon ๐
โจ
๐ฆ where this page comes from
- arch rolling: findutils 4.11.0-1 ยท GPL-3.0-or-later
- ubuntu stonking: findutils 4.11.0-2 ยท GFDL-1.3-or-later-no-invariants OR GFDL-1.3-or-later-no-invariants
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms