Recursively remove files

Does anyone have a solution to remove those pesky ._ and .DS_Store files that one gets after moving files from a Mac to A Linux Server?

specify a start directory and let it go? like /var/www/html/ down...


Solution 1:

change to the directory, and use:

find . -name ".DS_Store" -print0 | xargs -0 rm -rf
find . -name "._*" -print0 | xargs -0 rm -rf

Not tested, try them without the xargs first!

You could replace the period after find, with the directory, instead of changing to the directory first.

find /dir/here ...

Solution 2:

find /var/www/html \( -name '.DS_Store' -or -name '._*' \) -delete

Solution 3:

Newer findutils supports -delete, so:

find . -name ".DS_Store" -delete

Add -print to also get a list of deletions.

Command will work for you if you have an up-to-date POSIX system, I believe. At least it works for me on OS X 10.8 and works for others who've tested it on macOS 10.12 (Mojave).

Credit to @ephemient in a comment on @X-Istence's post (thought it was helpful enough to warrant its own answer).

Solution 4:

Simple command:

rm `find ./ -name '.DS_Store'` -rf
rm `find ./ -name '._'` -rf

Good luck!