Saturday, January 7, 2012

Find syntax to list huge-sized files and calculate total size

Situation
The disk space in one of the file-system (say /data1) is more 90% and you are asked to list out all the files which are more than 100 MB size and find the sum of total space occupied by listed files in Megabytes.

Solution
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 MB\n", sum/1024/1024}'\;

In Gigabytes:
# find /data1 -size +102400k -ls | awk '{sum += $7} END {printf "Total size: %6.2f GB\n", sum/1024/1024/1024}'\;

1 comment: