Finding the Disk Usage of a Folder on Linux

In this quick guide, we will show you how to easily check the disk usage of a folder on a Linux-based operating system.

Linux Find Folder Disk Usage

There are many times when you will want to be able to easily check the disk usage of a folder on your Linux system. This is especially true when you are running low on space and need to quickly work out what’s consuming space.

Luckily, Linux has a ton of built-in tools that make finding a directory’s disk usage relatively easy. In particular, we will be using a tool called “du.” du is short for disk usage and is one of the best ways to work out a directory’s space consumption.

Best of all, as this tool is a core part of Linux, it should be available on almost any Linux-based operating system, including the more popular distributions such as Ubuntu, Debian, and RHEL.

The methods we are showcasing in this tutorial are run purely within the terminal. If you are using a desktop-based system you can often open the terminal by pressing CTRL + ALT + T on your keyboard.

Getting the Disk Usage of a Directory on Linux

In the following sections, we will show you how to use the du command on Linux to check a directory’s disk usage.

This tool can be used in various ways, but overall, it makes finding the disk usage of a folder a very simple process, especially if you are stuck using the terminal.

Finding the Disk Usage of a Directory in Kilobytes

1. Linux’s du command is an incredibly easy tool to use and is one of the easiest ways to find the disk usage of a specific directory.

All you need to do is use “du” followed by the path to the directory you want to get the size of. By default, this command will return the size of the directory you specify and any subdirectories.

du DIRECTORY

2. For example, if we wanted to get the size of the folder “/home/pimyubu” and all its subfolders, we would run the following command.

du /home/pimyubu

Below, you can see how the du command returned the size of every directory in kilobytes. The final directory is always the one you specified and will give you the total folder size as it sits on your Linux system.

This command, by default, won’t show the size of the files it scans, but they are included in each calculation.

pimyubu@pimyubu2:~$ du /home/pimyubu
4       /home/pimyubu/Videos
70928   /home/pimyubu/bin
12      /home/pimyubu/Steam/logs
16      /home/pimyubu/Steam
12      /home/pimyubu/.ssh
4       /home/pimyubu/Desktop
12      /home/pimyubu/.gnupg
4       /home/pimyubu/Documents
4       /home/pimyubu/Templates
4       /home/pimyubu/Pictures
12      /home/pimyubu/.fontconfig
4       /home/pimyubu/Movies
4       /home/pimyubu/Public
4       /home/pimyubu/tmp
72      /home/pimyubu/.pki/nssdb
76      /home/pimyubu/.pki
4       /home/pimyubu/Music
4       /home/pimyubu/Downloads
1368688 /home/pimyubu

Using Linux to Get the Disk Usage of a Folder in a Human Readable Format

1. By default, the du command returns a folder’s disk usage in kilobytes. Luckily, like most tools on Linux, we can tell it to print the file size in a human-readable format.

For example, this will take the kilobytes value such as “70928” and convert it into a more readable number such as “70M“. In this case we could quickly tell that that particular folder is consuming 70 megabytes on our Linux system.

To get the disk usage of a folder in a human readable format, you will want to use the “-h” option.

du -h DIRECTORY

2. For this example, we will again get the disk usage of the “/home/pimyubu” directory on our Linux system. This time, however, we will get the command to print out the value in a human readable format.

The only real change here is that we used the “-h” option mentioned earlier.

du -h /home/pimyubu

With the result below, you can see how the size of each directory is now displayed in a readable format rather than in kilobytes.

pimyubu@pimyubu2:~$ du -h /home/pimyubu
4.0K    /home/pimyubu/Videos
70M     /home/pimyubu/bin
12K     /home/pimyubu/Steam/logs
16K     /home/pimyubu/Steam
12K     /home/pimyubu/.ssh
4.0K    /home/pimyubu/Desktop
12K     /home/pimyubu/.gnupg
4.0K    /home/pimyubu/Documents
4.0K    /home/pimyubu/Templates
4.0K    /home/pimyubu/Pictures
12K     /home/pimyubu/.fontconfig
4.0K    /home/pimyubu/Movies
4.0K    /home/pimyubu/Public
4.0K    /home/pimyubu/tmp
72K     /home/pimyubu/.pki/nssdb
76K     /home/pimyubu/.pki
4.0K    /home/pimyubu/Music
4.0K    /home/pimyubu/Downloads
1.4G    /home/pimyubu

Finding the Total Size of a Directory in Linux

1. If you are just interested in finding the total size of a specific directory in Linux, you will want to use the “-s” option.

This option tells the du command to summarize the file size as a single entry instead of displaying the size of each directory it discovers.

du -s DIRECTORY

2. To showcase how this works, let us use the du command and the “-s” option to get just the folder size of the “/home/pimyubu” directory.

du -s /home/pimyubu

With this result, you can see how Linux returned just the folder size in kilobytes. This is a great way to use this tool, as it doesn’t flood the terminal with information you may not want or need.

1368688 /home/pimyubu

If you were to combine the summarize option with the human-readable one, the result would look a bit like what we have shown below.

1.4G    /home/pimyubu

Find the Size of Files in a Directory on Linux

1. By default, Linux’s du command only returns the size of directories and does not display the size of files.

Linux, however, allows you to output the file size of both directories and files by utilizing the “-a” option.

du -a DIRECTORY

2. Let us show how this works by getting the disk usage of every file and directory within the “/home/pimyubu” directory.

We are also using the “-h” option alongside the “-a” option so that the result will be returned in a human readable format.

du -a -h /home/pimyubu

The result below shows how the command returned the file size of every folder and directory within our specified folder on Linux. This is useful if you are trying to determine what is consuming so much space within your directory.

pimyubu@pimyubu2:~$ du -ah /home/pimyubu
4.0K    /home/pimyubu/Videos
0       /home/pimyubu/.sudo_as_admin_successful
24M     /home/pimyubu/bin/ffmpeg
23M     /home/pimyubu/bin/ffplay
24M     /home/pimyubu/bin/ffprobe
70M     /home/pimyubu/bin
4.0K    /home/pimyubu/.bash_logout
8.0K    /home/pimyubu/homeassistant-supervised.deb
64M     /home/pimyubu/go.tar.gz
0       /home/pimyubu/Steam/.crash
0       /home/pimyubu/Steam/logs/stderr.txt
8.0K    /home/pimyubu/Steam/logs/bootstrap_log.txt
12K     /home/pimyubu/Steam/logs
16K     /home/pimyubu/Steam
4.0K    /home/pimyubu/.wget-hsts
100M    /home/pimyubu/google-chrome-stable_current_amd64.deb
4.0K    /home/pimyubu/.ssh/known_hosts
4.0K    /home/pimyubu/.ssh/known_hosts.old
12K     /home/pimyubu/.ssh
4.0K    /home/pimyubu/Desktop
4.0K    /home/pimyubu/.rediscli_history
4.0K    /home/pimyubu/test
4.0K    /home/pimyubu/.bashrc
4.0K    /home/pimyubu/.gnupg/trustdb.gpg
4.0K    /home/pimyubu/.gnupg/pubring.kbx
12K     /home/pimyubu/.gnupg
44K     /home/pimyubu/.bash_history
4.0K    /home/pimyubu/Documents
20K     /home/pimyubu/test.html
4.0K    /home/pimyubu/debian-binary
4.0K    /home/pimyubu/Templates
4.0K    /home/pimyubu/Pictures
4.0K    /home/pimyubu/.fontconfig/2b842ffd-a61d-4f79-a028-9a97f43fdec1-le64.cache-7
4.0K    /home/pimyubu/.fontconfig/CACHEDIR.TAG
12K     /home/pimyubu/.fontconfig
504K    /home/pimyubu/jammy_motion_4.6.0-1_amd64.deb
4.0K    /home/pimyubu/Movies
4.0K    /home/pimyubu/.profile
4.0K    /home/pimyubu/dconf.bkup
4.0K    /home/pimyubu/hello-world.go
4.0K    /home/pimyubu/Public
4.0K    /home/pimyubu/example1.txt
104M    /home/pimyubu/google-chrome-stable_current_amd64.deb.1
4.0K    /home/pimyubu/tmp
3.1M    /home/pimyubu/os-agent_1.6.0_linux_x86_64.deb
4.0K    /home/pimyubu/example2.txt
4.0K    /home/pimyubu/.pki/nssdb/pkcs11.txt
36K     /home/pimyubu/.pki/nssdb/key4.db
28K     /home/pimyubu/.pki/nssdb/cert9.db
72K     /home/pimyubu/.pki/nssdb
76K     /home/pimyubu/.pki
4.0K    /home/pimyubu/.lesshst
4.0K    /home/pimyubu/Music
998M    /home/pimyubu/Anaconda-Linux.sh
4.0K    /home/pimyubu/.Xauthority
4.0K    /home/pimyubu/Downloads
1.4G    /home/pimyubu

Conclusion

Hopefully, by this point in the tutorial, you will have a good idea of how to get the disk usage of a directory on your Linux system.

Being able to find the size of directories easily can make it easier when you are trying to track down whatever is consuming space on your system.

Please feel free to leave a comment below if you have had any issues determining the size of a folder.

If you found this guide to be helpful, we highly recommend that you check out our many other Linux guides.

Leave a Reply

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