Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] Command to find directories containing a particular size of data



On Sun, Apr 03, 2011 at 08:47:29AM +0200, Christian Horn wrote:
> On Sun, Apr 03, 2011 at 12:31:54PM +0900, Dave M G wrote:
> > 
> > However, what I'd really like is a sort of combination of the two. I
> > want to crawl through a whole directory tree, and find the directories
> > that contain 10MB or more of files.
> > 
> > When calculating the size of any one directory, I need to know just the
> > total size of *files* in that directory, but not including the sizes of
> > subdirectories in that total.
> 
> # bash, prints directories with >=5mb size
> for i in $(find /etc/ -type d); do 
> 	if [ $(du -sm $i|awk '{print $1}') -ge 5 ]; then 
> 		du -sm $i; 
> 	fi; 
> done

you save a number of forks and dus like this:

$ find ~/devel/linux-sony-2.6/ -type d -print0 | xargs -0 du -sS | \
	awk '$1 > 10000 { printf "%s (%d)\n", $2, $1 }'

Also note the -S to du: "do not include size of subdirectories".
-- 
mattia
:wq!


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links