bash xargs — run a command for each input line

# Pass multiple arguments at once (default)
find . -name "*.log" | xargs rm

# Pass one argument per call with -I
find . -name "*.txt" | xargs -I{} cp {} /backup/

# Null-delimited (safe with filenames containing spaces)
find . -name "*.txt" -print0 | xargs -0 rm

You need to run a command for each item from a list or command output, and the command does not accept stdin.

Parallel execution with -P

# Run up to 4 processes in parallel
find . -name "*.png" | xargs -P 4 -I{} convert {} {}.webp

Limit arguments per call with -n

# Run rm with at most 10 files at a time
find . -name "*.tmp" | xargs -n 10 rm

Preview the command before running

find . -name "*.log" | xargs -p rm
# xargs -p asks for confirmation before each call

Handle empty input safely

# Without -r, xargs runs the command even with empty input
find . -name "*.tmp" | xargs -r rm
# -r (--no-run-if-empty) skips execution when stdin is empty