I have a few directories, some with a depth of 3, which contain mixed file types. What I need to do is to rm -rf
all the subdirectories that do not contain filetype foo
.
Is this achievable with find
somehow?
I do know that I can use find like this:
find . ! -name '*.foo' -delete
to delete all files within the directories that do not contain any file of type *.foo
.
Now, how can I use this, to not only delete all unwanted files, but all directories and subdirectories which do not contain *.foo
?
/a/b
, andb
has no*.foo
files, but/a/b/c
has*.foo
files, obviously we don't want to runrm -rf /a/b
, right? In this case, I don't thinkrm -rf
is the right approach, maybe we need something likerm dir/*; rmdir dir
.some.foo
andsome.bar
, should it be deleted? Your question is not clear in this respect.