[xargs] Run commands in parallel

Created on November 30, 2026

Use -P, or --max-procs, to set how many processes xargs can run at once. In this example, -n 1 passes one argument to each invocation and -P 2 allows up to two invocations at a time.

printf '%s\n' 1 2 3 | xargs -n 1 -P 2 sh -c 'echo "item:$1"' _ | sort

The tasks can finish in any order. The final sort produces predictable output for this example.

item:1
item:2
item:3
Shell command