Reputation: 18699
I am looking for command to delete all files with a specific extension in a given folder. Both, for windows and mac.
Thanks!
Upvotes: 40
Views: 90063
Reputation: 285
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.
Upvotes: 3
Reputation: 1
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
Upvotes: -1
Reputation: 9
you can delete files by using "del" command followed by star del *.class del * .txt
Upvotes: 1
Reputation: 15374
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
Upvotes: 1
Reputation: 3399
Delete all files with extension .tmp
in current folder:
On Windows:
del *.tmp
On Mac:
rm -rf ./*.tmp
Delete all files with extension .tmp
in current folder Recursively (including sub-folders):
On Windows:
del /s *.tmp
On Mac:
find . -name '*.tmp' -delete
Upvotes: 111