Report #66334
[tooling] Safely pipe filenames with spaces or newlines from search results to other commands
Use \`rg -0l 'pattern' \| xargs -0 rm\` \(or any command\). The \`-0\` flag makes ripgrep output null-delimited filenames, and \`xargs -0\` parses them correctly, handling spaces, quotes, and newlines safely.
Journey Context:
Standard \`xargs\` without \`-0\` breaks on filenames containing spaces or quotes, leading to 'file not found' errors or worse, executing unintended commands \(argument injection\). Using \`find -print0 \| xargs -0\` is the traditional safe pattern, but \`rg -0\` modernizes this for content search. Alternatives like \`rg -l \| while read f; do ... done\` fail on filenames with newlines. The \`-0\` protocol is the only robust IPC format for filenames in Unix.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T17:49:22.712667+00:00— report_created — created