Placeholder Substitution

Basic -I{} — place argument anywhere in the command
printf '/tmp\n/var\n/etc\n' | xargs -I{} echo "directory: {}"
Shell expansion with sh -c — run complex commands per argument
find /home/evanusmodestus/atelier/_bibliotheca/domus-captures/docs/modules/ROOT/partials/codex/awk \
  -name '*.adoc' -print0 \
  | xargs -0 -I{} sh -c 'echo "=== {} ===" && wc -l < "{}"'
Per-file banner + head preview
find /home/evanusmodestus/atelier/_bibliotheca/domus-captures/docs/modules/ROOT/partials/codex/awk \
  -name '*.adoc' -print0 \
  | xargs -0 -I{} sh -c 'printf "\n--- %s ---\n" "{}" && head -3 "{}"'
Bulk sed via grep | xargs -I{} — find files containing pattern, then edit
# Dry run: preview files that would be edited
grep -rl 'xref:codex/text/' \
  /home/evanusmodestus/atelier/_bibliotheca/domus-captures/docs/modules/ROOT/pages/codex \
  | xargs -I{} sh -c 'echo "would edit: {}"'
# Actual edit (uncomment to run):
# grep -rl 'old-pattern' /path/to/dir | xargs -I{} sed -i 's/old-pattern/new-pattern/g' "{}"
Basename extraction — strip directory paths
find /home/evanusmodestus/atelier/_bibliotheca/domus-captures/docs/modules/ROOT/pages/codex/awk \
  -name '*.adoc' -print0 \
  | xargs -0 -I{} basename "{}"
-I implies -n1 — each argument gets its own invocation
# These are equivalent — -I{} already processes one arg at a time
printf 'alpha\nbeta\ngamma\n' | xargs -I{} echo "item: {}"
printf 'alpha\nbeta\ngamma\n' | xargs -n1 -I{} echo "item: {}"
# Verify: both produce 3 separate lines
Custom placeholder — use -I@ when braces conflict
printf 'alpha\nbeta\ngamma\n' | xargs -I@ echo "value=@"
Copy files to a target directory with -I{}
mkdir -p /tmp/xargs-copies
find /home/evanusmodestus/atelier/_bibliotheca/domus-captures/docs/modules/ROOT/partials/codex/awk \
  -name '*.adoc' -maxdepth 1 -print0 \
  | xargs -0 -I{} cp -v "{}" /tmp/xargs-copies/
Construct URLs from a list of paths
cat <<'EOF' > /tmp/endpoints.txt
/api/v1/health
/api/v1/status
/api/v1/config
EOF
xargs -a /tmp/endpoints.txt -I{} echo "https://localhost:8080{}"
Rename pattern — add prefix to files
mkdir -p /tmp/xargs-rename
touch /tmp/xargs-rename/{alpha,beta,gamma}.txt
ls /tmp/xargs-rename/ \
  | xargs -I{} sh -c 'mv /tmp/xargs-rename/"{}" /tmp/xargs-rename/"bak-{}"'