How to delete files with a certain extension from a folder and all of its subfolders

First, browse to the folder in which you want to delete files with a specific extension

cd /path/to/folder

Then delete the files with the extension .jpg

find . -type f -iname \*.jpg -delete
  • . tells to start searching in the current folder.
  • -type f tells find only to look for files.
  • -iname makes the search case insensitive.
  • -delete tells find to delete/remove all files found.

Change .jpg with the file extension you want to delete from a folder. I recommend running the command without -delete first to get a list of the files that will be removed when -delete is included in the command. This way a small typo won’t delete anything you didn’t intend to.