Check folder size in Bash

tom picture tom · May 21, 2013 · Viewed 293.5k times · Source

I'm trying to write a script that will calculate a directory size and if the size is less than 10GB, and greater then 2GB do some action. Where do I need to mention my folder name?

# 10GB
SIZE="1074747474"

# check the current size
CHECK="`du /data/sflow_log/`"
if [ "$CHECK" -gt "$SIZE" ]; then
  echo "DONE"
fi

Answer

Mingyu picture Mingyu · May 21, 2013

You can do:

du -h your_directory

which will give you the size of your target directory.

If you want a brief output, du -hcs your_directory is nice.