Unix delete all folders in a directory with a specific name

Adam picture Adam · Dec 26, 2012 · Viewed 9.2k times · Source

Hi I've got lots of folders with the name "@eaDir" all across one of my disks and I'd like to search through, find all of them and delete them and their contents.

I know this is probably a combination of the find and rm command but I can't quite figure them out. Can anyone help?

Answer

dschulz picture dschulz · Dec 26, 2012

Try this:

find . -type d -name '@eaDir' -print0 | xargs -rt0 rm -rv

Here's the same thing but using explicit long options for xargs:

find . -type d -name '@eaDir' -print0 | xargs --no-run-if-empty --verbose --null rm -rv

(using long options is always a good idea if you're writing scripts that will need to be maintained/reviewed by other people)

But before anything else:

man find
man xargs