xargs

Linux · Terminal · available in the simulator

What it does

Build and execute command lines from standard input.

Syntax

xargs [opciones] [comando]

Options and parameters

  • -n

    Maximum number of arguments per command line.

    ls | xargs -n1 echo
  • -I

    Replace occurrences of the specified string with each input item.

    ls | xargs -I{} cp {} /tmp
  • -0

    Input items are terminated by a null character; used with find -print0.

  • -P

    Run up to the specified number of processes in parallel.

Usage examples

  • printf '%s\n' a b | xargs echo
  • find . -type f -print0 | xargs -0 rm
  • ls | xargs -n1 echo
  • ls | xargs -I{} cp {} /tmp
Practise xargs

Related commands