Joe Joe - 5 months ago 13
Linux Question

How to remove folders with a certain name

In Linux, how do I remove folders with a certain name which are nested deep in a folder hierarchy?

The following paths are under a folder and I would like to remove all folders named

a
.

1/2/3/a
1/2/3/b
10/20/30/a
10/20/30/b
100/200/300/a
100/200/300/b


What Linux command should I use from the parent folder?

Answer

Use find, filter with only directories, filter by name, exec rmdir :

find -type d -name a -exec rmdir {} \;