I'm not too familiar with find
and managed to delete a ton of files by accident. I was wondering if anyone more experienced could explain where I went wrong.
I wanted to clean up all of the .DS_Store
and ._.DS_Store
files that my MacBook's Finder was barfing all over my Raspbian samba share.
- I have a hard drive attached to my raspberry pi, with some symlinks
in my home folder to the mounting point, hence the
-L
. - Some of the folders are owned by system users (e.g. apache) hence the
sudo
.
I ran the following to make sure that find
was targeting the right files:
hydraxan@raspberry:~ $ sudo find -L . -maxdepth 255 -name \*DS_Store\*
./.DS_Store
./Downloads/USBHDD1/._.DS_Store
./Downloads/USBHDD1/.DS_Store
./Downloads/USBHDD1/backups/ALAC/._.DS_Store
./Downloads/USBHDD1/backups/ALAC/Jeff Van Dyck - Assault Android Cactus OST/._.DS_Store
./Downloads/USBHDD1/backups/ALAC/Jeff Van Dyck - Assault Android Cactus OST/.DS_Store
./Downloads/USBHDD1/backups/ALAC/.DS_Store
./Downloads/USBHDD1/backups/._.DS_Store
./Downloads/USBHDD1/backups/.DS_Store
./Downloads/USBHDD1/backups/OriginalMusic/._.DS_Store
./Downloads/USBHDD1/backups/OriginalMusic/.DS_Store
./Downloads/USBHDD1/backups/OriginalMusic/FLAC/.DS_Store
./Downloads/USBHDD1/backups/Storage/._.DS_Store
./Downloads/USBHDD1/backups/Storage/.DS_Store
./Downloads/OriginalMusic/._.DS_Store
./Downloads/OriginalMusic/.DS_Store
./Downloads/OriginalMusic/FLAC/.DS_Store
./Downloads/ALAC/._.DS_Store
./Downloads/ALAC/Jeff Van Dyck - Assault Android Cactus OST/._.DS_Store
./Downloads/ALAC/Jeff Van Dyck - Assault Android Cactus OST/.DS_Store
./Downloads/ALAC/.DS_Store
All looks good!
I then added the -delete
flag to cause find
to remove the files it found:
hydraxan@raspberry:~ $ sudo find -L . -maxdepth 255 -delete -name \*DS_Store\*
find: cannot delete `./Documents': Not a directory
find: cannot delete `./Pictures': Not a directory
find: cannot delete `./Music': Not a directory
Once I realized it was trying to delete my symlinks for some reason, I punched Ctrl+C
and saved about half the data.
Documents, Pictures, and Music are toast. It was probably working on my giant Downloads folder that I put nearly everything in.
Why did find
delete all those files? Did I put -delete
in the wrong spot?