View Full Version : [ubuntu] How to recursively delete all files with a specific file extension starting from??

September 23rd, 2008, 06:59 AM
how do you recursively delete all files with a specific file extension starting from a folder

i'm assuming the command has rm, -R, and *.<extension> but don't know for sure


September 23rd, 2008, 07:02 AM
find /where/to/search/from/ -iname "*.<extension>" -exec rm '{}' ';'

find /where/to/search/from/ -iname "*.<extension>" -ok rm '{}' ';'

The second command will prompt for confirmation before it is removed, for each file.

September 23rd, 2008, 07:06 AM
First: Don't do this as root!!! Or not untill you're completly sure you did'nt make a fault in you're thinking and command.


rm -vRI /PATH/TO/STARTING/POINT/*<extension>

-v for verbose
-R for recursive going down the stream
-I safety net, just so you know you can say no when something goes wrong.

I strongly advice to supply the explicit path to the location where you want to start the recursive rm, just to protect yourself from issuing the command below /etc because you forgot you just did an 'cd /etc' two commands ago.

What I always do when I need to issue a command with some options I'm not sure off

man rm

September 23rd, 2008, 07:09 AM
Actually kpkeerthi,

what's the difference between you're approach and mine, regarding safety and processing that is?

September 9th, 2009, 07:25 AM
I could go for knowing the difference :)

June 6th, 2010, 10:51 PM
I think kpkeerthi's solution actually goes down to the sudirectories, whereas eentonig's solution seems to stay only on the specified directory.