Search This Blog

Tuesday, July 29, 2008

Count a sum of sizes of selected files in a directory

I would like to count how much space taking Qt4 libraries for the MacOSX universal build of one from our application. So I used following command:
du -m * | sort -nr | grep Qt | awk '{sum+=$1} END {print sum}'
  • du -m - print used size in megabytes (for directory do not forgot about -s option);
  • sort -nr - sort in reverse, numerical order;
  • grep Qt - left only lines with Qt (you can also first grep and next sort lines);
  • {sum+=$1} - adding a value from first column of each line to variable sum;
  • END {print sum} - printing variable sum on after going through all of lines.
Post a Comment