Command Line

Linux offers a nice way to retrieve file size information of folders, du. Like most commands, du offers many different options depending on what you want.

Display Size of Specific a folder

du /var/logs/apache2/error_log
419808	/var/log/apache2/

Display a Human readable version

When -h is used, the file size will be in a readable format, wherein file size will be suffixed with ‘B’, ‘K’, ‘M’ and ‘G’ for bytes, kilobyte, megabytes and gigabytes, respectively.

 du -h /var/log/apache2/
205M	/var/log/apache2/

Display File Size and all Files in the Folders

Along with the folder, files will also be included in the output if -a is used.

du -ah /var/log/apache2/
  0B	/var/log/apache2//accept.lock.191
  0B	/var/log/apache2//accept.lock.24
  0B	/var/log/apache2//accept.lock.25
  0B	/var/log/apache2//accept.lock.27
  0B	/var/log/apache2//accept.lock.40
 45M	/var/log/apache2//access_log
 11M	/var/log/apache2//dummy-host.example.com-access_log
2.8M	/var/log/apache2//dummy-host.example.com-error_log
  0B	/var/log/apache2//dummy-host2.example.com-access_log
  0B	/var/log/apache2//dummy-host2.example.com-error_log
146M	/var/log/apache2//error_log
  0B	/var/log/apache2//rewrite.lock
205M	/var/log/apache2/

Display Total File Size of Folders

The -c adds the total file size of all folders at the bottom

du -cah /var/log/apache2/
  0B	/var/log/apache2//accept.lock.191
  0B	/var/log/apache2//accept.lock.24
  0B	/var/log/apache2//accept.lock.25
  0B	/var/log/apache2//accept.lock.27
  0B	/var/log/apache2//accept.lock.40
 45M	/var/log/apache2//access_log
 11M	/var/log/apache2//dummy-host.example.com-access_log
2.8M	/var/log/apache2//dummy-host.example.com-error_log
  0B	/var/log/apache2//dummy-host2.example.com-access_log
  0B	/var/log/apache2//dummy-host2.example.com-error_log
146M	/var/log/apache2//error_log
  0B	/var/log/apache2//rewrite.lock
205M	/var/log/apache2/
205M	total

Related Article