How to remove all files with specific extension in folder?

Viewed 72959

I am looking for command to delete all files with a specific extension in a given folder. Both, for windows and mac.

Thanks!

5 Answers

Using the find command will do the job efficiently.
Inside the folder,
find . -name "*.ext" -type f -delete

/!\ - Use this first to know what you are going to delete recursively.
find . -name "*.bak" -type f

Also, refer to the man find to know more about about it.

you can delete files by using "del" command followed by star del *.class del * .txt

Before calling the del command you must also change the directory, for example a file bat could be like this

cd c:\MyFolderFullOfTmp
del *.tmp

This worked for me. I made a small function.

empty(){
   cd $1
   rm -rf *
   cd -
}

empty PATH/TO/DIRECTORY

You can also use this function.

empty(){
   rm -rf $1
   mkdir $1
}

empty PATH/TO/DIRECTORY

Related