In this tutorial we will look at how to check free space on Linux or Unix from the command line. It is important to keep track of the amount of free disk space you have, especially on a server where it is of utmost importance that data loss or downtime be kept to a minimum.
Linux and Unix systems come with a handy utility called df (short for disk free) which is used to display the amount of free space on any filesystem that the user invoking the command has read access to.
Open a terminal and enter the following command to get the free disk space in a "human readable" format:
df -h
The result should look something like:
Filesystem Size Used Avail Use% Mounted on /dev/xvda 9.9G 4.1G 5.4G 44% / devtmpfs 249M 112K 249M 1% /dev none 249M 0 249M 0% /dev/shm none 249M 68K 249M 1% /var/run none 249M 0 249M 0% /var/lock none 249M 0 249M 0% /lib/init/rw
As we can see from the output above, we have 5.4GiB of free space. Or, in other words, we have only used 44% of our 9.9GiB partition.
In case the df command with the -h flag does not work for you (some implementations do not have it, but it works on Ubuntu and others for sure), try using the -k flag (which shows 1024-byte units) like this:
df -k
The result should look something like:
Filesystem 1K-blocks Used Available Use% Mounted on /dev/xvda 10321208 4279524 5622256 44% / devtmpfs 254504 112 254392 1% /dev none 254712 0 254712 0% /dev/shm none 254712 68 254644 1% /var/run none 254712 0 254712 0% /var/lock none 254712 0 254712 0% /lib/init/rw
As you can see, the percentage use remains the same but space is quoted in kilobytes instead. It's just another way of displaying the same data to the user.
And that is how you check free space on Linux. We hope you found this tutorial useful, and that it helps you to keep your server from running out of space.