The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > OS Specific Forums > Linux
Google UNIX.COM


Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
deleting specific lines from all files in a directory vrms UNIX for Dummies Questions & Answers 3 04-25-2008 08:08 AM
deleting empty files in a directory berlin_germany Shell Programming and Scripting 5 01-26-2007 12:47 PM
shell script: deleting files from a directory onlyc Shell Programming and Scripting 1 07-09-2006 03:41 AM
Accidentally deleting directory/files milhan UNIX for Advanced & Expert Users 4 08-27-2003 06:59 AM
Deleting A Directory! firefinger UNIX for Dummies Questions & Answers 2 10-19-2001 09:17 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #8  
Old 04-13-2008
rubin's Avatar
Registered User
 

Join Date: Nov 2007
Posts: 215
Quote:
Originally Posted by radoulov View Post

What's wrong with:
rm -r */

That's right, sometimes we miss the simple...
Reply With Quote
Forum Sponsor
  #9  
Old 04-13-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
yes sometimes we just miss the simplest things. however take note it still suffers from "argument too long" issues if there are too many directories ( maybe there's a workaround somewhere)
Code:
# ls -p | grep "/" | wc -l
31998
# rm -r */
bash: /bin/rm: Argument list too long
# ls -p|awk '/\/$/&&!/\./' | xargs -i rm -rf "{}"
# ls -p | grep "/" | wc -l
0
Reply With Quote
  #10  
Old 04-13-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milano, Italia/Варна, България
Posts: 1,858
Quote:
Originally Posted by ghostdog74 View Post
yes sometimes we just miss the simplest things. however take note it still suffers from "argument too long" issues if there are too many directories ( maybe there's a workaround somewhere)
[...]
My post was based on the OP requirement (~10dirs).

Anyway, I don't think ls and awk are needed in this case
and I'd try to handle pathological dirnames (embedded spaces, newlines or other special characters) .
Reply With Quote
  #11  
Old 04-13-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
Quote:
Originally Posted by radoulov View Post
My post was based on the OP requirement (~10dirs).
yes, that's why rm -f */ is the simplest solution to his problem. No doubt about that.
Reply With Quote
  #12  
Old 04-13-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milano, Italia/Варна, България
Posts: 1,858
Quote:
Originally Posted by ghostdog74 View Post
yes, that's why rm -f */ is the simplest solution to his problem. No doubt about that.

Just to make it clear,
I don't think ls and awk are needed in the case you describe (argument list too long).

Code:
for d in */;do rm -r "$d";done
Or better (needs to be adjusted for xargs that doesn't support the null option):

Code:
xargs -0n1000 rm -r < <(printf "%s\000" */)
If you have zsh:

Code:
autoload -U zargs
zargs *(/) -- rm -r

Last edited by radoulov; 04-13-2008 at 10:36 AM. Reason: corrected
Reply With Quote
  #13  
Old 05-02-2008
Registered User
 

Join Date: Apr 2008
Posts: 10
damn,
i was just experimenting rm -rf */
i just typed /*
Reply With Quote
  #14  
Old 05-02-2008
grial's Avatar
El UNIX es como un toro
 

Join Date: Jun 2006
Location: Madrid (Spain)
Posts: 531
find /path -type d -exec rm -rf {} \;
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:39 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0