How do I get the size of a directory on the command line in Linux?

There are some situations when you need to check size of directories on your Linux server. Usually it’s due to logging which can consume your hard disk, especially if you have heavy traffic web site or if you log some common type events. Log rotation can help but you need to configure it properly according to your hard disk size.

First thing you might find useful is following command:

df -h

which will show size and usage of your disk’s logical partitions. Now when you know what partition is critical you can check specific directories, so you can clean it or tweak log rotation script (if you have one for particular log). Just type:

du -sh file_path

where file_path is patch to the wanted directory, for example:

du -sh /var/log/nginx

If you want to see size of all the directories just type:

du -sh *

And for the size of current directory type:

du -sh .

Leave a Reply

Your email address will not be published. Required fields are marked *