Bash 5 reference · Text and System Tools

xargs (Linux command)

Build and run commands from input lines, in batches or in parallel; pair with find -print0 and xargs -0 for safe file names.

Bash 5

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

xargs [-0] [-n N] [-P N] [-I {}] COMMAND

Parameters

ParameterDescription
-0 Input is NUL-separated.
-n N At most N arguments per command.
-P N Run N commands in parallel.
-I {} Replace {} with each input line.

Examples

Batches of arguments
printf '%s\n' a b c d | xargs -n 2 echo batch:

Output

batch: a b
batch: c d

Run this on your computer — see “Get Started” for setup.

Safe with spaces
touch 'my file.txt' other.txt
find . -name '*.txt' -print0 | sort -z | xargs -0 -I {} echo "found: {}"

Output

found: ./my file.txt
found: ./other.txt

Run this on your computer — see “Get Started” for setup.

Was this page helpful?