No matter how high-capacity your storage drive is, you always need to see how much space you have used and what files are using it. While there are ways to do this from the GUI in Linux, as always, you get more detail by using the terminal command line. Terminal tools are especially useful for users who are monitoring remote systems, for example busy system administrators connecting over a secure shell connection. In this tutorial, we’ll look at various ways of using the terminal to check disk usage enabling us to see what storage space is left on our system no matter where we may be.

All the commands in this how-to will work on most Linux machines. We’ve used an Ubuntu LTS install but you could run this how-to on aRaspberry Pi. All of the how-to is performed via the Terminal. You can open a terminal window on most Linux machines by pressingctrl, altandt.

A disk in a data center

Using df to Check Disk Usage in Linux

A simple approach to check all disk usage on a system is to simply issue thedfcommand from the home directory in a terminal window.

You should see a long output list. This list of items includes not only the physicalbest hard driveconnected to your system but also any separate drive partitions, as well as virtual drives and temporary drives on your system.

How To Check Disk Usage in Linux

To spot physical drives or partitions on physical drives look out for listings that begin with /dev/ such as /dev/sda1/. In this case dev stands for device and indicates that the item following it is a physical drive or a partition on a physical drive. Finally, you’ll notice that by default the df command outputs the size of the drive or partition in kilobytes.

The raw output generated by thedfcommand can be overwhelming. We can add some simple arguments to thedfcommand to make the output a little easier to read and understand.

How To Check Disk Usage in Linux

1.Use the -h argumentto display the sizes and usage in megabytes and gigabytes. The-hargument refers to “human readable”.

Get Tom’s Hardware’s best news and in-depth reviews, straight to your inbox.

How To Check Disk Usage in Linux

2.Usedf -h /to see a broad overview of disk usage. This command will show the disk usage for the main filesystem (/)

3.Passdf -hplus the location of a driveto see information on that drive only.On our machine our main physical drive is mounted at/dev/sda2/which is common but may be different on your system.

How To Check Disk Usage in Linux

On another test system our NVMe drive was located at /dev/nvme0n1p6 Adding a location todfallows us to explore just one area of a file system or one specific drive making the output more focussed and readable.

Specify df Results by File System Type

Using the-targument in combination with other arguments we can return results only for a specific type of file system. For example FAT, NTFS, ext etc.

1.List results ofdfcommand but only for ext4 type filesystems.

Jo Hinchliffe

On our example system our main physical drive filesystem is ext4, but you may use any filesystem name you may have on your own system such as, FAT, exFAT, ext3, ext2 etc.

2.Re-run the command adding the-hargument.It’s important that thetargument is placed at the end of the argument list as thetargument expects to be followed by a filesystem type. If for example you want to add the-hargument you must add it before thetas shown below.

Exploring Linux Disk Usage with the du Command

Often we might simply want to check how much room a file or directory is using. Theducommand is useful for this and works in a similar way to thedfcommand we looked at earlier. In the following examples we have used our Music directory which contains 3 subdirectories containing mp3’s. you’re able to use any directory with contents on your system to try these commands.

1.Move to a directory, list its contents and then check disk usage.

Note that similar to the df command, in its standard form the du command returns values in kilobytes. The output of this command is quite straightforward: it lists the size of each sub directory and then the name and then finally on the last line returns the sum of all the subdirectory sizes to give the directory disk usage.

2.Add the-hargumentto makedureturn results in megabytes and gigabytes.

3.Simplify the output to just show the total directory size.If we just want to know the total size of the directory and its subdirectories, adding-sas an argument will return just the total.

4.Specify a location for theducommand.

Similar to other linux commands we don’t always need to run the du command from within the target directory, rather we can specify a path to a target directory. This can be a relative path, from our current location, or an absolute path.

The df and du commands are deceptively simple but immensely powerful. No matter if you are a relative newcomer or a seasoned sysadmin, both commands are absolutely essential for the smooth running of your Linux machines. At the basic level, each command gives you the information that you need. With the addition of our suggested arguments, these commands are ready to to be part of your sysadmin toolkit.

Jo Hinchliffe is a UK-based freelance writer for Tom’s Hardware US. His writing is focused on tutorials for the Linux command line.