Quick note for self. Simple bash loop to find out the size of each directory in the existing directory. This script is useful if you are running our of disk space and want to quickly find out the offending directory.
[code]for dir in $(find ./ -maxdepth 1 -type d); do echo ${dir}; du -ch ${dir} | grep -i total; done [/code]
Breaking this down
- The find command prints out a list of directories. You can modify it to do recursive lookups by just removing the -maxdepth option. This output is fed into the bash loop
- du gets the size of all the files (and sub directories) in the directory and grepping it for total gives you the total size of the directory
This is how I do it:
for i in $(ls -F | grep /$); do du -sh $i; done;
I derived a find syntax something similar to this (using awk – sum) for finding the Total size occupied by huge-sized files on a specified directory:
To list all the files in /data1, which are more than 100 MB size.
# find /data1 -size +102400k -exec du -sh {} ;
To find the sum of total space occupied by listed files.
In Megabytes:
# find /data1 -size +102400k -ls | awk ‘{sum += $7} END {printf “Total size: %8.4f MBn”, sum/1024/1024}’;
In Gigabytes:
# find /data1 -size +102400k -ls | awk ‘{sum += $7} END {printf “Total size: %6.2f GBn”, sum/1024/1024/1024}’;
Ref: http://ashok-linux-tips.blogspot.in/2012/01/find-syntax-to-list-huge-sized-files.html
Very nice.. Thx Ashok.