Linux: Get folder size of all sub-folders in command line

This command shows the list of sub-folders of the current folder with their size:

du -h --max-depth=1

This command shows the list of sub-folders of a specific folder with their size:

du -h --max-depth=1 /path/to/folde

To get the disk size, run this command:

df -sh

To remember between df and du, here is a tip:

  • df: Disk Free
  • du: Disk Usage

Sometimes you see the outputs of these commands are different. One situation that I usually see is I get the disk full notification, while du tells me I have some GB to use.

After looking for a while, I notice that it’s the Apache issue. Apache keeps its log in the memory, and that makes the df fails. Restarting Apache fixes the bug:

service apache2 restart

This solution is provided in StackOverflow.

One important thing to remember is when you see disk is full, try to remove Apache’s log first (in /var/log/apache2). It usually takes up to GB!

Leave a Reply


Subscribe to our newsletter to receive news and tutorials about WordPress and web development.

BPF - New WordPress Business Theme - Intro Price $29 ONLY!!! Get it now →