You need to set the globstar
option (introduced in Bash 4) for the recursive globbing to work
From the Bash reference manual
globstar
If set, the pattern ‘**’ used in a filename expansion context will match all files and zero or more directories and subdirectories. If the pattern is followed by a ‘/’, only directories and subdirectories match.
So this should work
shopt -s globstar
rm -f **/*.png
Or alternatively with find
and the delete
action
find . -name '*.png' -delete
Note on the "-r" switch of rm
:
-r
switch "remove directories and their contents recursively" (Source: man rm). By default, rm
can't remove directories. The switch doesn't change how filename expansion or globbing works.