The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
need solution for this quickly. please quickly. p.palakj.shah UNIX for Dummies Questions & Answers 5 04-17-2008 12:27 AM
Deleting Files bc4 UNIX for Dummies Questions & Answers 1 01-25-2007 08:27 PM
Deleting files BG_JrAdmin SUN Solaris 1 11-28-2006 10:17 PM
Deleting old files shiroh_1982 Shell Programming and Scripting 2 06-21-2006 01:42 AM
Deleting the files livetaurean19 Shell Programming and Scripting 0 06-16-2005 01:16 PM

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-28-2002
Registered User
 

Join Date: Nov 2001
Location: New Zealand
Posts: 333
deleting 100k log files quickly

I've walked into a while loop gone bad.....which has created 100k+ log files.

Is it quicker removing the files with rm pattern* or actually removing the entire directory with rm -rf dir/

It's taking ages (hours) either way ...just curious if one is goig to be quicker than the other...or is it actaully using the same logic for deletion?
__________________
Pete
Forum Sponsor
  #2  
Old 08-28-2002
RTM's Avatar
RTM RTM is offline
Hog Hunter
 
Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
Don't know which is faster if either - care to run your loop and time them both?

  #3  
Old 08-28-2002
Registered User
 

Join Date: Nov 2001
Location: New Zealand
Posts: 333
Yeah sure....perhaps I could mow your lawns as well - and wash your car?

It's done now....didn't 'seem' to be quicker either way... am just curious about the logic that rm -rf uses vs rm *. Does it simply expand the 'options' much as rm * does?
__________________
Pete
  #4  
Old 08-28-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
Do I understand that you removed 100,000 files or more? If so "rm *" would not work. A whole bunch of "rm pattern*" could do it. So could "ls | xargs rm". I would go with "rm -rf /directory" just as you did. It's the least work for me.

Which is easiest on the system? The difference will be minor, it's the 100,000 unlink() system calls that take forever. But "rm -rf /directory" is one process while the other techniques are many processes. That already gives it a edge. What's more, the other techniques are creating processes with long argument lists. The shell will fork() and exec() to create a process. exec() causes a new program to overlay the program that called exec(). But first, the envirinment and the arguments must be saved so that they can be passed to the program.

So you probably saved several seconds!

But seriously, I appaud your curiosity. An understanding of the internal operation of unix can often be very useful. But in this case, anyway yout it, you still had to do 100,000 unlinks.
  #5  
Old 08-28-2002
Registered User
 

Join Date: Nov 2001
Location: New Zealand
Posts: 333
I did patterns..... but I like the xargs option....

So if I saved myself several seconds - I guess I spent more than that figuring out that I did!

I'm guessing from your explanation then that the effort (ergo time) involved in removing one file of 1Mb is considerably less than 1,000 odd files of 1k.
__________________
Pete
  #6  
Old 08-29-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
Quote:
Originally posted by peter.herlihy
I'm guessing from your explanation then that the effort (ergo time) involved in removing one file of 1Mb is considerably less than 1,000 odd files of 1k.
Absolutely! And this would be true even if the 1000 files were scattered around in several different directories. But unix searches directories sequentially. When you put thousands of files in one directory the performance goes into the toilet.
  #7  
Old 08-29-2002
oombera's Avatar
Registered User
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
Quote:
But unix searches directories sequentially. When you put thousands of files in one directory the performance goes into the toilet.
You're saying it's easier on Unix to remove a thousand files from a thousand different directories than it is to remove them from one directory?

Or do you mean that it removes files sequentially within the directory.. in which case, sequentially or randomly, it's still removing every file in the directory, so why is that slower?
Google The UNIX and Linux Forums
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:18 PM.


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