Skip to main content
1 of 2
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

To search for directories called Index in or below the current directory, and then to delete these, you would use find like so:

find . -depth -name Index -type d -exec rm -r {} \;

This does a depth-first search for the specific directories you are interested in and invokes rm -r on each of them in turn. We need to do a depth-first search (with -depth) as we might otherwise remove directories that haven't yet been visited by find, which would generate errors.

Use -path '*/Contents/Index' in place of the -name test if you need the Index directory to be a child directory of a Contents directory.

Using the zsh shell, or the bash shell with its globstar shell option set, you may also be able to use

rm -r ./**/Index/

or

rm -r ./**/Contents/Index/

This would call rm -r with a list of pathnames of directories called Index (assuming all the parts of the directory path are non-hidden, and assuming you're ok with also deleting directories symbolically linked via the name Index, and assuming the list of matching pathnames is not thousands of entries long).

Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k