|
 |
|
 |
04-09-2008, 10:13 PM
|
#1 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,446
|
remove thousands of files from a directory
i have a directory with about 650,000 files in it that i need to remove. is the best way to do it with find piped to xargs?
__________________
Mike
|
|
|
04-10-2008, 12:05 AM
|
#2 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,446
|
this worked much faster than find
__________________
Mike
|
|
|
04-10-2008, 03:43 AM
|
#3 (permalink)
|
|
Recruit
Join Date: Sep 2005
Location: Loughborough, England, UK
Posts: 12
|
|
|
|
04-10-2008, 08:28 AM
|
#4 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,446
|
Quote:
Originally Posted by ShadyCraig
|
that's what i tried first. it can't handle that many files.
__________________
Mike
|
|
|
04-10-2008, 09:13 AM
|
#5 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,694
|
# find . -exec rm -f {} \;
Would be my choice.
|
|
|
04-10-2008, 07:39 PM
|
#6 (permalink)
|
|
Java fanboy
Join Date: Aug 2003
Posts: 1,140
|
Can't you just go up a directory then "rm -rf <dir>"?
Barring that, redhead's idea would be my next choice.
|
|
|
04-10-2008, 08:36 PM
|
#7 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,446
|
Quote:
Originally Posted by Belisarius
Can't you just go up a directory then "rm -rf <dir>"?
Barring that, redhead's idea would be my next choice.
|
no, that's why i needed an alternative. 650,000 files is too many for rm to handle.
find was taking forever. ls | xargs completed within a minute.
__________________
Mike
|
|
|
04-10-2008, 11:33 PM
|
#8 (permalink)
|
|
Recruit
Join Date: Sep 2005
Location: Loughborough, England, UK
Posts: 12
|
Quote:
Originally Posted by sde
that's what i tried first. it can't handle that many files.
|
I though it might be, but I didn't want to try it to find out
Cheers
|
|
|
04-11-2008, 12:43 AM
|
#9 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,446
|
so, how does one get 650,000 files in the first place? i had a user on my server who never checked their system account for the last year or so. their mail file got very big.
i recently installed dovecot, which puts each email into an individual file, instead of all emails in 1 file, and vua la. 650k message is now 650k files 
__________________
Mike
|
|
|
04-11-2008, 08:09 AM
|
#10 (permalink)
|
|
Senior Contributor
Join Date: Mar 2005
Posts: 651
|
650k file != 650k files * 4k
Sometimes it's better to have 1 file instead of 650k because a fle of 1kb takes up 4kb of space.
Based on file system this can vary from 1k (Raiser) to 64k (FAT32).
That's why you always format a drive based on what tasks a server may do 
__________________

UT: Ultra-kill... God like!
|
|
|
04-11-2008, 09:10 AM
|
#11 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,446
|
no, that was supposed to be 650k messages, i.e. emails in that spool file. it was actually a couple GB in size.
__________________
Mike
|
|
|
04-13-2008, 11:50 AM
|
#12 (permalink)
|
|
Jack of all trades
Join Date: Feb 2005
Location: Los Angeles
Posts: 596
|
Find - exec is much slower than find |xargs rm, because in the case of n files find -exec will invoke rm n times whereas find|xargs will only invoke rm n mod <max commandline args> times, so you see a major speed up in terms of process invocation overhead.
The ultimate power combo is find -print0|xargs -0 rm -f
It uses null characters rather than whitespace to separate the output/input so it won't break in the face of files with spaces or newlines embedded in the names.
__________________
Stop intellectual property from infringing on me
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 02:40 AM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|