What does the -n option of xargs do?

The -n option of xargs limits the number of arguments passed to each command execution. For example, if you use xargs -n 2, it will pass at most 2 arguments to the command for each execution.

Here’s a quick example:

echo {1..10} | xargs -n 2 echo "Processing batch:"

This will output:

Processing batch: 1 2
Processing batch: 3 4
Processing batch: 5 6
Processing batch: 7 8
Processing batch: 9 10

In this case, each execution of echo receives exactly 2 arguments.

0 Comments

no data
Be the first to share your comment!