image
image

Go Back   macosx.com > Mac Help Forums > Unix & X11

Reply
 
Thread Tools
  #1  
Old June 8th, 2005, 10:47 PM
Registered User
 
Join Date: Jun 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
jcooper11 is on a distinguished road
Recursive rm w/ wildcard?

Want to do recursive rm w/ a wildcard, deleting all files named, for example, *.jpg, but leaving others, going all the way down inside a folder/directory.
Tried variations on ....
rm -r *.jpg
Not allowed? Another approach?
tia
Reply With Quote
  #2  
Old June 8th, 2005, 11:25 PM
lurk's Avatar
Mitä?
 
Join Date: Mar 2002
Location: Land o' skeeterz
Posts: 2,076
Thanks: 0
Thanked 0 Times in 0 Posts
lurk is on a distinguished road
find . -name "*.jpg" | xargs rm

YMMV and it will break for file with spaces in their names, the space case is left as an exercise for the reader.
Reply With Quote
  #3  
Old June 8th, 2005, 11:26 PM
lurk's Avatar
Mitä?
 
Join Date: Mar 2002
Location: Land o' skeeterz
Posts: 2,076
Thanks: 0
Thanked 0 Times in 0 Posts
lurk is on a distinguished road
Also you may want to check it with xargs -n 1 echo as a sanity check.
Reply With Quote
  #4  
Old June 9th, 2005, 07:30 AM
Mac Metal Head
 
Join Date: Nov 2003
Posts: 821
Thanks: 0
Thanked 0 Times in 0 Posts
HateEternal is on a distinguished road
I am pretty sure that command should work, maybe try it with a capital R
Reply With Quote
  #5  
Old June 9th, 2005, 12:48 PM
Who, me?
 
Join Date: Feb 2005
Location: Near to Philly.
Posts: 382
Thanks: 0
Thanked 0 Times in 0 Posts
chornbe is on a distinguished road
rm -fR /*.jpg <enter>

yep.
Reply With Quote
  #6  
Old June 9th, 2005, 11:53 PM
lurk's Avatar
Mitä?
 
Join Date: Mar 2002
Location: Land o' skeeterz
Posts: 2,076
Thanks: 0
Thanked 0 Times in 0 Posts
lurk is on a distinguished road
That will not get /foo/bar.jpg

The thing to remember is that the shell does the * expansion (globbing) and not rm. So you are always saying recursively remove these directories. Not recurse through these directories looking for these files.
Reply With Quote
  #7  
Old June 10th, 2005, 02:41 AM
HomunQlus's Avatar
Artifical Lifeform
 
Join Date: Mar 2005
Location: Dublin, Ireland
Posts: 384
Thanks: 0
Thanked 0 Times in 0 Posts
HomunQlus is on a distinguished road
rm -rf [filenames]

rm -rf *.jpg
__________________

Mac OS X User for life

"You know what is worse than being all alone in the night, captain?
To be all alone in the crowd."
- Ambassador Delenn


Reply With Quote
  #8  
Old June 10th, 2005, 02:55 AM
ScottW's Avatar
Founder
 
Join Date: Sep 2000
Location: Overland Park, KS
Posts: 3,175
Thanks: 0
Thanked 6 Times in 3 Posts
ScottW is on a distinguished road
at root /

sudo rm -Rf *.jpg

Bad things can happen, watch out.
Reply With Quote
Reply

Thread Tools

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump


All times are GMT -5. The time now is 03:50 AM.


Mac Support® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2000-2008 DigitalCrowd, Inc.