Skip to content

xargs command

Build and run commands from standard input.

On this page

Syntax

xargs [options] [command]

Provided by the findutils package. Run man xargs for the full manual.

Common options

OptionWhat it does
-n NPass at most N arguments per command
-I {}Replace {} with each input item
-0Items are separated by NUL (use with find -print0)
-P NRun up to N commands in parallel
-rDon't run the command if the input is empty
-pAsk before each command

Examples

  1. Delete files found by find

    find . -name "*.tmp" -print0 | xargs -0 rm -f
  2. One argument per command

    echo a b c | xargs -n 1 echo
  3. Use a placeholder

    cat urls.txt | xargs -I {} curl -sO {}
  4. Run 4 jobs in parallel

    ls *.png | xargs -P 4 -I {} optipng {}
  5. Grep inside the files find returns

    find . -name "*.conf" | xargs grep -l "listen"

xargs guides

← All Linux commands · Suggest a fix

Back to top