How to delete all images from a directory/subdirectories
I have a directories with a few subdirectories within it, and I want to rm all the image files ending in .jpg within the directory and also its subdirectories too. What command can I use to do this?
|
Hi,
- First cd to the dir in question cd /path/to/jpgdirs, - Then use find and the appropriate options: find . -type f -iname "*.jpg" this will find and print all the jpg's (and is a check to see if all is ok, do this before the next command!), - If all is well, extend the find command to remove the jpg's: find . -type f -iname "*.jpg" -exec rm -f {} \; Hope this helps. |
For safety you can also use -ok instead of -exec: this will ask you confirmation before deleting files:
Code:
find . -type f -iname "*.jpg" -ok rm -f {} \; |
All times are GMT -5. The time now is 07:08 AM. |