Given:
- I have a tree structure with folders
EmptyMe
on different levels EmptyMe
directories contain sub-directories and files
Required:
- Empty contents of
EmptyMe
directories (including their sub-directories), while keeping those directories (not deleting them).
Question:
What's the Unix command to recursively find all EmptyMe
directories from current level and delete all of their contents (including sub-directories), while keeping EmptyMe
directories on the disc?
My attempt:
$ find . -name 'EmptyMe' -type d -exec rm -- {} +
rm: cannot remove `./a/b/c/d/EmptyMe': Is a directory
As you can see, that command attempted to remove EmptyMe
, as opposed to its contents.
find . -name 'EmptyMe' -type d -exec find {} -type f -delete \;
Let me know if you want this as actual answerEmptyMe
.-mindepth 1
for the nested command, and remove-type f
cause OP wants to remove directories too.