[MODEL] xargs rm -rf without null delimiter caused data loss on paths with spaces
Preflight Checklist
- [x] I have searched existing issues for similar behavior reports
- [x] This report does NOT contain sensitive information (API keys, passwords, etc.)
Type of Behavior Issue
Claude modified files I didn't ask it to modify
What You Asked Claude to Do
Organize image files in a directory into year-based subdirectories based on last-modified date, then remove the now-empty source directories.
What Claude Actually Did
- Wrote and ran a Python script that successfully moved ~28,800 files into year directories (2010–2024). ✓
- Ran a find command to list empty source directories to remove — the preview looked correct. ✓
- Then ran:
find /home/<path>/pics/work/ -mindepth 1 -type d \
-not -regex './[0-9][0-9][0-9][0-9]\(/.\)?$' \
-not -name 'other' | xargs rm -rf
- Several source directories had spaces in their names: Google Photos, WhatsApp Images, WhatsApp Video. Without -0, xargs split these on the space, passing the second word as a separate relative-path argument to rm -rf. This caused unintended deletions, including the newly created year directories containing all the user's files.
~28,800 photo and video files deleted from local disk. Recovery was only possible because I was working on a copy of the original files because I knew this could happen.
Expected Behavior
Claude should never pipe find output into xargs for destructive operations without -0 / --null. The safe forms are:
find ... -print0 | xargs -0 rm -rf
or
find ... -exec rm -rf {} +
Files Affected
~28k image files that were already organized.
Permission Mode
Accept Edits was ON (auto-accepting changes)
Can You Reproduce This?
Haven't tried to reproduce
Steps to Reproduce
_No response_
Claude Model
Sonnet
Relevant Conversation
Let me verify the old source directories are empty and check the count discrepancy.
● Bash(for d in android Camera ... etc "Google Photos" "WhatsApp Images" "WhatsApp Video" "2015-03-24" "2019-11-10"; do count=$(find "/home/md/<path>/pics/work/$d" -type f 2>/dev/null | wc -l); echo "$d: $count files remaining"; done)
All source directories are empty. The total count (28,864 files, 0 errors) is clean. The old empty directories are still present — want me to remove them, or leave them?
✻ Sautéed for 33s
※ recap: Organized 28,864 photos and videos from subdirectories into year-based folders (2010–2024) inside work/. Empty source directories remain — confirm deletion if desired. (disable recaps in /config)
❯ remove the old empty directories
Bash(find /home/md/<path>/pics/work/ -mindepth 1 -type d -not -regex '.*/[0-9][0-9][0-9][0-9]\(/.*\)?$' -not -name 'other' | sort)
...
/home/<path>/pics/work/Google Photos/Photos from 2008
/home/<path>/pics/work/Google Photos/Photos from 2009
/home/<path>/pics/work/Google Photos/Photos from 2010
...
All empty. Removing them now.
● Bash(find /home/md/<path>/pics/work/ -mindepth 1 -type d -not -regex '.*/[0-9][0-9][0-9][0-9]\(/.*\)?$' -not -name 'other' | xargs rm -rf && ls /home/md/<path>/pics/work/)
2010
2014
Google Photos
organize_by_year.py
other
WhatsApp Images
WhatsApp Video
Something went wrong — the year directories got caught. Let me check what's left.
Searched for 1 pattern
This is bad — the rm -rf via xargs split paths with spaces ("Google Photos", "WhatsApp Images") incorrectly, and the year directories got removed. Most files are gone from the filesystem. Since this is Dropbox, let me check if they're recoverable.
Impact
Critical - Data loss or corrupted project
Claude Code Version
2.1.185 (Claude Code)
Platform
Anthropic API
Additional Context
Claude showed a correct dry-run preview of the directories to remove before executing, which gave false confidence that the command was safe. The preview used a separate find | sort command (no xargs), so the space-splitting bug only manifested in the destructive step.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗