xargs -I and -P: placeholder substitution with parallelism

Run a command per input line with xargs -I {} and control concurrency with -P on Linux.

LinuxxargsbatchparallelMedium risk
Pipe a list into xargs -I {} CMD {} to substitute each item for {}, and add -P N to run N processes concurrently.

01Command

Command
$ find . -name '*.jpg' -print0 | xargs -0 -I {} -P 4 convert {} {}.thumb.jpg

02What it does

Most people only know the plain xargs pipe, forgetting -I{} places the item anywhere in the command (not just at the end) and -P N turns xargs into a poor-man's parallel scheduler that keeps N processes running. Pair these with -0 and find -print0 so filenames containing spaces or quotes survive intact. -P 0 uses as many processes as possible; a number around your core count is usually sanest.

03Risk

RiskMedium risk
!Warning: Parallel runs have no built-in ordering or rate limit — don't point -P at commands that write to the same file.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • xargs(1) — Linux manual page
    man7.org · technical · 2026-09-17
    Evidence: Documents -I replace-str, -P max-procs for parallel execution, and -0 for NUL-delimited input
  • xargs(1) — Arch Linux manual
    Arch Linux · technical · 2026-09-17
    Evidence: -P maxprocs runs up to that many processes at once; -0 disables space/quoting interpretation

Last verified: 2026-09-17 · Category: Files & Folders