Check disk space usage in Ubuntu

Published: October 22, 2022

Check disk space usage in Ubuntu

Running out of disk space is not something which any user would like. If we realize that early, then we can take necessary measures in time. We, generally, divide our storage disk in one or more partitions. These partitions can help us manage our data well. For instance, multimedia files in X partition, and all our work files in Y partition. But, there could be times when our disk space would show that there is enough space left. But, a partition would show otherwise.

So, to avert such a situation we need to monitor disk space and partitions therein at regular intervals. And, when we run out of space in a partition and there is enough space left on disk then, we can transfer data between partitions.

In Ubuntu or in other Linux distributions, various tools are available to help us monitor disk space. One such command-line tool is df, which we cover in next section.

Check disk space usage in Ubuntu

To check for disk space, use df command-line utility. So, open a terminal and issue the following -

df -h

where, -h options helps us have the data in a human readable format.

You would notice that output here is divided in five columns - Filesystem, Size, Used, Avail, Use% and Mounted on. The data in the columns is self-explanatory. Its about the filesystem's total size, how much of it is available, the use percentage and where it is mounted.

In the output, you would also notice tmpfs filesystem. It is temporary filesystem which keeps all its files in virtual memory.

Apart from that, if you choose to list inode information then use -i option with df -

df -i

To ensure only local filesystems are listed, use -l option -

df -l

If you want list only a specific type of filesystem then,

df -t <fs_type>

For instance, for ext4 -

df -t ext4

On the other hand, to exclude a filesystem type from the output -

df -x <fs_type>

For instance, to exclude tmpfs -

df -x tmpfs

In conclusion, monitor disk space at regular intervals. And, df command-line tool helps us do exactly that.