xargs -I {}: Place Each Item in the Command
xargs -I {} substitutes each input item into a placeholder, running the command once per item.
When the item is not the last argument, or you need it in the middle of a command, -I gives you a placeholder to drop it in exactly where it belongs.
What it does
xargs -I <repl> reads one item per line, substitutes it for every occurrence of the replacement string in the command, and runs the command once for that item. Choosing {} as the replacement string is convention. Using -I implies one item per command and turns off whitespace splitting within a line.
Common usage
cat services.txt | xargs -I {} kubectl rollout restart deploy/{}
ls *.png | xargs -I {} cp {} backup/{}
find . -name '*.env' | xargs -I {} sh -c 'echo "loading {}"; cat {}'Options
| Flag | What it does |
|---|---|
| -I <repl> | Replace repl with one input item per command run |
| {} | Conventional replacement string used with -I |
| (implies -L 1) | Each input line becomes one command run |
| -i (deprecated) | Old GNU spelling that defaults the repl to {} |
In CI
Because -I runs one command per item, it is slower than the default packing but far more predictable when each item needs its own invocation. To restore parallelism, combine -I {} with -P to run those per-item commands concurrently.
Common errors in CI
A line longer than the replacement limit triggers "xargs: argument line too long" because -I caps each line at 255 bytes on some implementations. Items with spaces are kept whole by -I (good), but a literal {} elsewhere in your command also gets replaced, which can surprise you. The deprecated -i prints a warning on GNU xargs; use -I instead.