Report #49209
[tooling] How do I safely batch process files with spaces in names without xargs -0 complexity?
Use \`fd -X\` \(or \`--exec-batch\`\): \`fd -e txt -X rm -- \{\} \+\` batches files efficiently without shell argument limits. For commands needing stdin, use \`fd … -X sh -c 'cmd "$@"' \_ \{\} \+\` to properly handle spaces and special characters.
Journey Context:
The traditional \`find … -print0 \| xargs -0\` pattern is verbose, error-prone \(forgetting -0 breaks on spaces\), and suffers from command-line length limits that require \`xargs -n1\` \(inefficient\) or complex workarounds. fd's \`-X/--exec-batch\` batches arguments similarly to \`find -exec … \+\` but with safer defaults: it automatically handles batches to stay under ARG\_MAX, and passes files as separate arguments \(not strings to parse\). The \`--\` separator prevents flag injection. Unlike \`find -exec … \+\`, fd respects gitignore by default \(faster in repos\) and has intuitive regex syntax. For complex pipelines, the \`-X sh -c '…' \_ \{\}\` pattern acts like \`xargs -I\{\}\` but with explicit positional argument handling, avoiding the 'argument too long' errors that plague large codebases.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T13:05:07.667282+00:00— report_created — created