Get Directory Size on Linux

Get Directory Size on Linux

As a Linux user, you may often find yourself needing to determine the size of a directory to manage disk space efficiently or track down large files that might be taking up valuable storage. Fortunately, Linux provides a simple and effective method to get the size of a directory and its contents. This tutorial demonstrates how to get directory size on Linux.

The most common and straightforward way to get the size of a directory on Linux is by using the du command. This command recursively calculates the disk space used by a directory and its subdirectories.

For example, to get the total size of the /var directory, you can run the following command:

sudo du -sh /var
  • -s - displays only the total size of the specified directory, suppressing individual sizes of subdirectories.
  • -h - shows sizes in a more readable format.

Output example:

13G /var

To get the summarized disk usage of all immediate subdirectories within the /var directory on Linux, use the asterisk symbol (*) as shown below:

sudo du -sh /var/*

Output example:

2.0M    /var/backups
115M    /var/cache
4.0K    /var/crash
6.5G    /var/lib
4.0K    /var/local
0       /var/lock
1.1G    /var/log
4.0K    /var/mail
4.0K    /var/metrics
4.0K    /var/opt
0       /var/run
8.2M    /var/snap
52K     /var/spool
100K    /var/tmp
5.0G    /var/www

Leave a Comment

Cancel reply

Your email address will not be published.