How to remove all folders with foldername X within a directory using osx terminal

directory, macos, terminal

Solution

"cd" to root of directory Y

then (assuming the folder name is "X", type in):

"`find . -name X -exec rm -rf {} \;`" (and be incredibly careful about where you start this "`find`" from... you only want to do this within your Y directory).

I do this kind of thing all the time to remove old/busted repository directories (like "`.svn`"), which I suspect is what you may also be doing as well.

And now would probably be a smart time for me to remind you that "Time Machine" is a great thing to have enabled on your Macintosh.

Problem

There is a folder named X located within a number of subfolders of root directory Y. I want to delete all folders named X that are present in Y and all of it's subfolders. I want to do this using osx Terminal. The folder can be located anywhere downstream of Y at any level, so I want to use a more systematic approach than just using `rm -r` for every locations I find.

Original source