Skip to main content
4 of 5
added 215 characters in body
Stéphane Chazelas
  • 587.8k
  • 96
  • 1.1k
  • 1.7k

If I understand correctly, you want something like:

find . -depth -print0 | perl -0lne ' if ("$_/" =~ m{/Caches(/.*)}s && $1 !~ m{/Snapshots/}) {rmdir $_ or unlink $_}' 

 

 Before: After: . . ├── a ├── a │   ├── a │   ├── a │   └── Caches │   └── Caches │   ├── a │   └── a │   │   └── Snapshots │   └── Snapshots │   │   └── a │   └── a │   ├── b └── b │   │   └── a └── c │   └── c └── b ├── c └── Caches ├── a │   └── foo │   └── a └── b └── a 
Stéphane Chazelas
  • 587.8k
  • 96
  • 1.1k
  • 1.7k