Tuesday, August 11, 2009

sorting directories by disk usage

I needed to sort directories by disk usage using du and sort , but there was a problem with dirs that start with "-"

$du -s *

gives this error "du: invalid option --"

So i had to put the directory list result in a file:

$ find . -maxdepth 1 -type d -name '*' -print0 >file_list.lst

then i used the --files0-from

$ du -sm --files0-from file_list.lst | sort -n

seems that i needed to show the timestamp --time and maybe to exclude the "thumbs.db" from the report --exclude="thumbs.db"

$ du -sm --exclude="thumbs.db" --time --files0-from file_list.lst | sort -n

2 comments:

Unknown said...

what's wrong with these?

du -sm -- * | sort -n

du -m --max-depth=1 | sort -n

Popa Adrian Marius said...

Thanks that it's ok , only if you have a huge list then is better to have it in a file , also i need to process that list from an php file