<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel> 

	<title>Comments on: Deleting very large directory</title>
	<link>http://ask.metafilter.com/88428/Deleting-very-large-directory/</link>
	<description>Comments on Ask MetaFilter post Deleting very large directory</description>
	<pubDate>Thu, 10 Apr 2008 09:56:43 -0800</pubDate>
	<lastBuildDate>Thu, 10 Apr 2008 09:56:43 -0800</lastBuildDate>
	<language>en-us</language>
	<docs>http://blogs.law.harvard.edu/tech/rss</docs>
	<ttl>60</ttl>

	<item>
		<title>Question: Deleting very large directory</title>
		<link>http://ask.metafilter.com/88428/Deleting-very-large-directory</link>	
		<description>How to delete a huge directory on Linux &lt;em&gt;without&lt;/em&gt; overloading the system? &lt;br /&gt;&lt;br /&gt; I&apos;ve looked at &lt;a href=&quot;http://ask.metafilter.com/60733/Quickly-delete-a-directory-containing-many-files&quot;&gt;this question&lt;/a&gt; which is basically my exact situation, but I can&apos;t get any of the solutions described too work without killing the system.&lt;br&gt;
&lt;br&gt;
I&apos;ve tried:&lt;br&gt;
rm -rf mydir&lt;br&gt;
nice rm -rf mydir&lt;br&gt;
nice -n 19 find mydir -type f -exec rm -v {} \;&lt;br&gt;
nice -n 19 rm -rf mydir&amp;amp;&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
And many other combinations of rm, find rm, nice find rm, etc, but all cause the server load to rise to dangerous levels quickly (I kill the process when `top` hits 20, I&apos;m assuming the machine would hang if allowed to continue).&lt;br&gt;
&lt;br&gt;
So is it possible to remove a directory with a lot of files without killing the server?</description>
		<guid isPermaLink="false">post:ask.metafilter.com,2008:site.88428</guid>
		<pubDate>Thu, 10 Apr 2008 09:42:14 -0800</pubDate>
		<dc:creator>justkevin</dc:creator>
		
			<category>rm</category>
		
			<category>unix</category>
		
			<category>linus</category>
		
			<category>directory</category>
		
			<category>files</category>
		
			<category>delete</category>
		
	</item> <item>
		<title>By: nicwolff</title>
		<link>http://ask.metafilter.com/88428/Deleting-very-large-directory#1301555</link>	
		<description>&lt;code&gt;find mydir -type f -print0 | perl -0 -MTime::HiRes=sleep -ne &apos;unlink; sleep .1;&apos;&lt;/code&gt;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.88428-1301555</guid>
		<pubDate>Thu, 10 Apr 2008 09:56:43 -0800</pubDate>
		<dc:creator>nicwolff</dc:creator>
	</item><item>
		<title>By: nicwolff</title>
		<link>http://ask.metafilter.com/88428/Deleting-very-large-directory#1301560</link>	
		<description>(Or &lt;code&gt;sleep .05&lt;/code&gt; or &lt;code&gt;.01&lt;/code&gt; or whatever doesn&apos;t crush your CPU.)</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.88428-1301560</guid>
		<pubDate>Thu, 10 Apr 2008 09:58:32 -0800</pubDate>
		<dc:creator>nicwolff</dc:creator>
	</item><item>
		<title>By: flabdablet</title>
		<link>http://ask.metafilter.com/88428/Deleting-very-large-directory#1301564</link>	
		<description>find mydir -type f | while read; do rm -v &quot;$REPLY&quot;; sleep 0.2; done</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.88428-1301564</guid>
		<pubDate>Thu, 10 Apr 2008 10:02:07 -0800</pubDate>
		<dc:creator>flabdablet</dc:creator>
	</item><item>
		<title>By: flabdablet</title>
		<link>http://ask.metafilter.com/88428/Deleting-very-large-directory#1301566</link>	
		<description>Sorry, should be&lt;br&gt;
&lt;br&gt;
find mydir -type f | while read -r; do rm -v &quot;$REPLY&quot;; sleep 0.2; done&lt;br&gt;
&lt;br&gt;
just in case any of your filenames have backslashes in them.  This won&apos;t remove files with newlines in their names, but those are pretty rare.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.88428-1301566</guid>
		<pubDate>Thu, 10 Apr 2008 10:05:52 -0800</pubDate>
		<dc:creator>flabdablet</dc:creator>
	</item><item>
		<title>By: flabdablet</title>
		<link>http://ask.metafilter.com/88428/Deleting-very-large-directory#1301572</link>	
		<description>Follow it up with&lt;br&gt;
&lt;br&gt;
find mydir -depth -type d | while read -r; do rmdir -v &quot;$REPLY&quot;; sleep 0.2; done&lt;br&gt;
&lt;br&gt;
to remove the directory tree, if you have tens of thousands of subdirectories and rm -rf is still too harsh.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.88428-1301572</guid>
		<pubDate>Thu, 10 Apr 2008 10:09:33 -0800</pubDate>
		<dc:creator>flabdablet</dc:creator>
	</item><item>
		<title>By: TravellingDen</title>
		<link>http://ask.metafilter.com/88428/Deleting-very-large-directory#1301573</link>	
		<description>It would be interseting to know both how many files are there (ls |wc -l) and what OS/filesystem is in use.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.88428-1301573</guid>
		<pubDate>Thu, 10 Apr 2008 10:10:13 -0800</pubDate>
		<dc:creator>TravellingDen</dc:creator>
	</item><item>
		<title>By: flabdablet</title>
		<link>http://ask.metafilter.com/88428/Deleting-very-large-directory#1301577</link>	
		<description>If there are enough files that rm -rf hangs you up, you don&apos;t want to be doing anything that sorts their names - TravellingDen&apos;s curiosity would be best served with&lt;br&gt;
&lt;br&gt;
find mydir -type f | wc -l</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.88428-1301577</guid>
		<pubDate>Thu, 10 Apr 2008 10:12:16 -0800</pubDate>
		<dc:creator>flabdablet</dc:creator>
	</item><item>
		<title>By: dws</title>
		<link>http://ask.metafilter.com/88428/Deleting-very-large-directory#1301583</link>	
		<description>I did some experiments on this a few years back. Between the 2.4 and 2.6 kernel series, directories became better and adding and opening files, but much slower at deleting them.&lt;br&gt;
&lt;br&gt;
Once you&apos;ve solved your immediate problem, the next step is to avoid building huge directories. One approach is to partition files into subdirectories based on something easily computable, such as the first few characters of the filename, or the md5/sha1 hash of the filename if that gets you a better distribution. This is how git (a distributed version control system) manages huge numbers of files (e.g., the source files for Linux, so if this is how Linux does it for Linux, it&apos;s an approach worth considering).</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.88428-1301583</guid>
		<pubDate>Thu, 10 Apr 2008 10:14:52 -0800</pubDate>
		<dc:creator>dws</dc:creator>
	</item><item>
		<title>By: justkevin</title>
		<link>http://ask.metafilter.com/88428/Deleting-very-large-directory#1301598</link>	
		<description>Using flabdablet&apos;s method of counting files (and nicwolf&apos;s method of deleting them), there&apos;s currently a little over 5 million, dropping at a rate of a few hundred a second.  Top seems stable, hovering around 3.0, plus or minus.&lt;br&gt;
&lt;br&gt;
It&apos;s Red Hat ES, kernel 2.6.18.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.88428-1301598</guid>
		<pubDate>Thu, 10 Apr 2008 10:35:21 -0800</pubDate>
		<dc:creator>justkevin</dc:creator>
	</item><item>
		<title>By: pharm</title>
		<link>http://ask.metafilter.com/88428/Deleting-very-large-directory#1301603</link>	
		<description>ionice will probably help:&lt;br&gt;
&lt;br&gt;
$ ionice -c 3 rm -rf &amp;lt;dir&amp;gt;&lt;br&gt;
&lt;br&gt;
puts rm in the &quot;idle&quot; io scheduler class, which should mean that it only gets to do IO when nobody else wants to.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.88428-1301603</guid>
		<pubDate>Thu, 10 Apr 2008 10:40:37 -0800</pubDate>
		<dc:creator>pharm</dc:creator>
	</item><item>
		<title>By: unixrat</title>
		<link>http://ask.metafilter.com/88428/Deleting-very-large-directory#1301725</link>	
		<description>The ionice/nice command loads &lt;strong&gt;should NOT concern you &lt;/strong&gt;when they rise.  &lt;br&gt;
&lt;br&gt;
&lt;strong&gt;Trust the scheduler &lt;/strong&gt;- trust the system.   The scheduler *knows* your command has no priority and it &lt;em&gt;will &lt;/em&gt;move it aside for other applications when they request it.  The load rises because the system starts doing what you requested.&lt;br&gt;
&lt;br&gt;
The load of a system is just a measure.  The scheduler will still do the correct thing when requested.  You are not &quot;killing&quot; anything, I promise.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.88428-1301725</guid>
		<pubDate>Thu, 10 Apr 2008 12:08:26 -0800</pubDate>
		<dc:creator>unixrat</dc:creator>
	</item><item>
		<title>By: pharm</title>
		<link>http://ask.metafilter.com/88428/Deleting-very-large-directory#1301751</link>	
		<description>The scheduler only knows that the command has the same priority as every other command unless you tell it otherwise.&lt;br&gt;
&lt;br&gt;
Although I agree that a high load value isn&apos;t in and of itself a bad thing.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.88428-1301751</guid>
		<pubDate>Thu, 10 Apr 2008 12:23:09 -0800</pubDate>
		<dc:creator>pharm</dc:creator>
	</item><item>
		<title>By: cschneid</title>
		<link>http://ask.metafilter.com/88428/Deleting-very-large-directory#1301965</link>	
		<description>Agreed with using ionice, and letting the thing chug away.  It will let you use your computer for anything else, since everything else will get higher priority to the disk.  And the delete will go when nothing else wants to.&lt;br&gt;
&lt;br&gt;
No reason to keep load down, use the computer to it&apos;s fullest.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.88428-1301965</guid>
		<pubDate>Thu, 10 Apr 2008 14:49:04 -0800</pubDate>
		<dc:creator>cschneid</dc:creator>
	</item><item>
		<title>By: flabdablet</title>
		<link>http://ask.metafilter.com/88428/Deleting-very-large-directory#1302118</link>	
		<description>Also: if you&apos;re regularly creating directories with millions of files in them, you might want to consider putting those on a ReiserFS file system.  Reiser is good at that.  But read &lt;a href=&quot;http://zork.net/~nick/mail/why-reiserfs-is-teh-sukc&quot;&gt;this&lt;/a&gt; first.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.88428-1302118</guid>
		<pubDate>Thu, 10 Apr 2008 17:21:05 -0800</pubDate>
		<dc:creator>flabdablet</dc:creator>
	</item>
	</channel>
</rss>
