LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How to delete all images from a directory/subdirectories (https://www.linuxquestions.org/questions/linux-general-1/how-to-delete-all-images-from-a-directory-subdirectories-719509/)

SentralOrigin 04-16-2009 02:36 AM

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?

druuna 04-16-2009 02:45 AM

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.

colucix 04-16-2009 02:54 AM

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.