recursively delete all files except some especific types

Viewed 1848

I want to recursively delete all files in some folders except those who have .gz extension. Normally I use

find /thepath -name "foo" -print0 | xargs -0 rm -rf

to recursively delete all folders named "foo" in the /thepath. But now I wan to add an exclusion option. How that is possible?

For example, the folder structure looks like

 .hiddenfolder
 .hiddenfolder/bin.so
 arc.tar.gz
 note.txt
 sample

So I want to delete everything but keep arc.tar.gz

2 Answers
Related