LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 04-16-2009, 02:36 AM   #1
SentralOrigin
Member
 
Registered: Jul 2005
Distribution: Gentoo, Ubuntu
Posts: 318

Rep: Reputation: 30
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?
 
Old 04-16-2009, 02:45 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
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.
 
Old 04-16-2009, 02:54 AM   #3
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,488

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
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 {} \;
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying a Directory into Another Directory with Subdirectories oadvantage Linux - Newbie 4 03-06-2006 05:27 PM
why can't the /bin directory contain subdirectories? learnfast Linux - Newbie 2 03-09-2005 11:31 AM
Image Viewer question (view images subdirectories) gflores Linux - Newbie 1 02-21-2005 01:25 AM
How can i delete Directories and Subdirectories? OrganicX Linux - Newbie 15 03-05-2003 08:48 PM
delete files / keep subdirectories? lhorstman Linux - Newbie 2 01-10-2003 03:01 PM


All times are GMT -5. The time now is 01:06 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration