What command should I use to rm all .png files in a folder and subfolder?

6,830

You were very close:

find -type f -iname '*.png' -exec rm {} \;

As edwinksl pointed out, using -delete flag also works:

find -type f -iname '*.png' -delete

In bash shell alone we can do

shopt -s globstar
rm ./**/*.png

This, however, might suffer from Arguments list too long error, if number of files expanded is large, or environment passed to the command is also large. As always, remember to append echo rm ./**/*.png to see what will actually run.

Share:
6,830

Related videos on Youtube

user285884
Author by

user285884

Updated on September 18, 2022

Comments

  • user285884
    user285884 over 1 year

    I started with this based off of another question I had:

    find -type f -iname '*.png' -exec rm
    

    that clearly didn't work, but am I atleast warm?

    • edwinksl
      edwinksl over 7 years
      You could replace the -exec rm part with -delete.