Build and execute command lines from standard input
xargs -0 {null} -a {arg-file} -d {delimiter} -E {flag-e} -e {eof} ๐ null ๐ arg-file ๐ delimiter ๐ flag-e ๐ eof xargs -0 {null} -a {arg-file} -d {delimiter} -E {flag-e} -e {eof} Sandbox: execFile · Timeout: 30s
system.file.xargs system.file.search system.file.process system.file.copy system.file.move system.file.delete | Name | Type | Required | Default | Description | Aliases |
|---|---|---|---|---|---|
null | string | No | - | items are separated by a null, not whitespace | -0, --null |
arg-file | file | No | - | read arguments from FILE, not standard input | -a, --arg-file |
delimiter | string | No | - | items in input stream are separated by CHARACTER | -d, --delimiter |
flag-E | string | No | - | set logical EOF string; if END occurs as a line | -E |
eof | string | No | - | equivalent to -E END if END is specified | -e, --eof |
flag-I | string | No | - | same as --replace=R | -I |
replace | string | No | - | replace R in INITIAL-ARGS with names read | -i, --replace |
max-lines | integer | No | - | use at most MAX-LINES non-blank input lines per | -L, -L, --max-lines |
flag-l | string | No | - | similar to -L but defaults to at most one non- | -l, -L |
max-args | integer | No | - | use at most MAX-ARGS arguments per command line | -n, -A, --max-args |
open-tty | string | No | - | Reopen stdin as /dev/tty in the child process | -o, --open-tty |
max-procs | integer | No | - | run at most MAX-PROCS processes at a time | -P, -P, --max-procs |
interactive | string | No | - | prompt before running commands | -p, --interactive |
process-slot-var | string | No | - | set environment variable VAR in child processes | --process-slot-var |
no-run-if-empty | string | No | - | if there are no arguments, then do not run COMMAND | -r, --no-run-if-empty |
max-chars | integer | No | - | limit length of command line to MAX-CHARS | -s, -C, --max-chars |
show-limits | string | No | - | show limits on command-line length | --show-limits |
verbose | string | No | - | print commands before executing them | -t, --verbose |
exit | string | No | - | exit if the size (see -s) is exceeded | -x, --exit |
help | string | No | - | display this help and exit | --help |
version | string | No | - | output version information and exit | --version |
null | string | No | - | items are separated by a null, not whitespace | -0, --null |
Basic usage with null
xargs ${null} Display help message
xargs --help Find all file names ending with .pdf, then remove them.
find -name \*.pdf | xargs rm The above, however, is better-written without xargs:
find -name \*.pdf -exec rm {} \+ Although it's best to use find's own functionality, in this situation.
find -name \*.pdf -delete Find all file names ending with '.pdf' and remove them. This approach also handles filenames with '\n' and skips '*.pdf' directories. The xargs(1) flag `-r` is equivalent to `--no-run-if-empty`, and the use of `-n` will in this case group execution by 10 files.
find -name \*.pdf -type f -print0 | xargs -0 -r -n 10 rm If file names may contains spaces, you can use the xargs(1) flag `-I` and its proceeding argument to specify the filename placeholder, as in find(1)'s use of `{}` in `-exec`. Although find(1)'s `{}` needs not be cuddled by quotes, - xargs(1) does.
find -name \*.pdf | xargs -I {} rm -r '{}' Print a list of files in the format of `*FILE=`. The use of xargs(1) flag `-n` here with its argument of `1` means to process the files one-by-one.
find -name \*.pdf | xargs -I {} -n 1 echo '&{}=' The above is, however, much faster, more efficient, and easier without xargs.
find -name \*.pdf -printf '&%f=\n' Group words by three in a string.
seq 1 10 | xargs -n 3 Alternatively, and more efficiently, use Bash brace expansion, if available.
printf '%d ' {1..10} | xargs -n 3 xargs is a command-line utility for build and execute command lines from standard input.
xargs -0 {null} -a {arg-file} -d {delimiter} -E {flag-e} -e {eof}