Deluxe Blog Tips About Projects

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!

Subscribe to the Newsletter

Subscribe to get my latest content by email. I won't send you spam. Unsubscribe at any time.