Weblog entry #5 for HWilton

A way to list folder size
Posted by HWilton on Tue 13 Mar 2007 at 13:10
Tags:
I'm using "du -mc" to get the size of each directory. But then i'm trying to limit that list to one level deep.
But i couldnt find the proper grep syntax to do that.

Filtering the du -mc output to echo only lines that has one slash, would do the trick ... but how ?!
du -mc | grep "/"
the last command isnt filtering anything (obviously)
And man grep gives cryptic help on the subject :
       A regular expression may be followed by one of several repetition oper-
       ators:
       ?      The preceding item is optional and matched at most once.
       *      The preceding item will be matched zero or more times.
       +      The preceding item will be matched one or more times.
       {n}    The preceding item is matched exactly n times.
       {n,}   The preceding item is matched n or more times.
       {n,m}  The  preceding  item  is	matched at least n times, but not more
	      than m times.

i've tried
du -mc | grep "/"{1}
but doesnt output anything at all, then

 

Comments on this Entry

Posted by Arthur (66.28.xx.xx) on Tue 13 Mar 2007 at 13:16
[ Send Message | View Weblogs ]
Try du --max-depth=1 and if you like human readable megabytes and gigabytes, du -h --max-depth=1

[ Parent | Reply to this comment ]

Posted by alfadir (141.58.xx.xx) on Tue 13 Mar 2007 at 13:17
[ Send Message | View Weblogs ]
What about
du --max-depth=1 -mc
Check the manpage. (I had du version 5.97)

[ Parent | Reply to this comment ]

Posted by HWilton (15.203.xx.xx) on Tue 13 Mar 2007 at 13:27
[ Send Message | View Weblogs ]
Fantastic - thanks a lot and its even better than my workaround using grep ! cos i can do it from within a sub-folder Thanks !

[ Parent | Reply to this comment ]

Posted by w1d3 (85.145.xx.xx) on Tue 13 Mar 2007 at 14:57
[ Send Message | View Weblogs ]
Hi, I often use du with -s switch:
du -sh
for getting the size of whole directory,
du -sh *
for listing also file and 1st level directory sizes.. in this way you can use
du -sh */
for your purpose. The drawback is that it doesn't list hidden files and directories.. but you can use it when you are sure that there aren't any in the directory :) And the last one, often used by me:
du -sk * | sort -n

[ Parent | Reply to this comment ]

Posted by andmalc (24.226.xx.xx) on Thu 19 Apr 2007 at 19:20
[ Send Message ]

The advantage of wld3's solution is you can use your shell globbing patterns to refine which parts of the tree are selected. For instance, if you're using zsh, you can get a size summary excluding tmp and backup directories to a depth of one like this:

du -shc */*^tmp^backup

[ Parent | Reply to this comment ]

User Login

Username:

Password:

[ Advanced Login ]

Register Account

Quick Site Search