[TriLUG] [bash] get total size of list of directories?

Nick Goldwater trilug at dogstar1.com
Sun Apr 13 21:52:52 EDT 2008


Below will give you the size of the folder:
du --si -S /path/to/folder/

This will present a list of folder sizes:
#!/bin/bash
if [ “a$1″ != “a” ]; then
cd $1
fi
du --si */ .[^.]*/ | sort -n | while read a; do echo ” $a”; done | sed -r 's/^\ *([\ 0-9]{3})([\ 0-9]{3})([ 0-9]{3})\ *(.*)\/$/\1 \2 \3 \4/' | egrep -v "k\ " 

Nick

----- "Tom Roche" <Tom_Roche at pobox.com> wrote:

| Can one get the total size of a list of directories via shell
| scripting? I know I can do something like
| 
| $ find /this -maxdepth 1 -type d | grep -ve 
| '/this$\|norThat$\|norTheOther$' | xargs du -hs
| 
| but that just gives me the size of each dir in the list, and
| 
| $ find /this -maxdepth 1 -type d | grep -ve 
| 'this$\|norThat$\|norTheOther' | du -hs
| 
| fails oddly: value reported is wildly low, so I suspect it's just
| getting one directory then returning. How to get the sum of all?
| 
| TIA, Tom Roche <Tom_Roche at pobox.com> first trilug post from my eee!
| -- 
| TriLUG mailing list        :
| http://www.trilug.org/mailman/listinfo/trilug
| TriLUG Organizational FAQ  : http://trilug.org/faq/
| TriLUG Member Services FAQ : http://members.trilug.org/services_faq/



More information about the TriLUG mailing list