Before downloading a huge file or package, it is recommended to check whether you have enough space for that action.
And the easiest way to check the free space in your Ubuntu machine is to use the df command with the
-h flag as shown:
The above command will get a list all the file systems, including mounting points. You can see the actual disk partitions for the entries that start with /dev. And you can see how much free space is left on each disk partition.
As you can see, my root partition has 849 GB available. Out of a total size of 907 GB, only 2% is used.
Want more details? Here you have it.
Check free space using the df command
The df (disk free) command is used to find out the disk space usage on Linux.
But the output is not the most human-readable when executed without any options:
So it is recommended to use the
-h flag with the df command to get the output in human-readable form:
Now, let's break down the output:
tmpfs: It is a temporary file system that is used to keep files in virtual memory, and you may ignore this.
/dev/: This is where the mounted drives are shown, including the internal and external drives. This is what you generally want.
/dev/loop: If you are using Ubuntu or anything else with snap packages enabled, you'd find various entries of loop devices that are nothing but snap packages mounted in your system.
And if you want to include the type of the file system, you can add the
-T flag as shown:
Check free space using the duf command
The duf command is nothing but modern advancement of du and duf combined. The du command is used for checking directory size and disk usage. You already saw the use of df command above. The combined command does a pretty good job showing you the available free disk space.
But first, let's have a look at how it can be installed in Ubuntu.
To install duf in Ubuntu, all you have to do is execute the following:
sudo apt install duf
Once done, you can start duf by simply typing
duf in your terminal:
For most users, the given output will do the job but if you want to inspect the usage by a specific drive you can do that too.
To investigate a specific drive, all you have to do is append the name of the filesystem or the mounting point:
For example, here, I looked for my HDD and my home directory:
duf /home /media/sagar/HDD/
Similarly, if you want to list the specific filesystem only, then you'd have to use the
--only-fs flag as shown:
duf --only-fs filesystem
For example, here's how I listed all the ext4 drives:
duf --only-fs ext4
To learn more about duf, I would recommend checking out our detailed guide on duf command:
There's a modern alternative to df
There's a modern implementation of the df command called pydf. Which provides a more modern and visually appealing output compared to the traditional df command.
To install pydf, you can use the following command:
sudo apt install pydf
Once done, you can execute the
pydf in your terminal, and it should get you much better visuals than the df command:
Pretty neat. Isn't it?
Running out of free space?
Once you use the df command, you'd have a better idea of what is taking and how much storage.
And if it looks more cluttered than it should, then here are multiple ways to free up space on Ubuntu:
I hope you will find this helpful.