Linux Basics: Find The Amount Of Free Disk Space On File Systems With The ‘df’ Utility

Hi guys,

In this tutorial I will show you how to use the df command to perform some practical and useful stuff in your own linux machine. You are not going to get  a full documentation of this file system disk space usage reporter here but rather some very important skills valuable in the linux world.

Do you like to know the amount of disk space available on a filesystem? I do. Open a new terminal (CTRL+ALT+T  In Ubuntu) and run the following command.

df

As you guys can see we did not call the df utility with any argument, but the information provided by it seems to be very readable and useable for a linux geek.

What information do we get by running the above command? Before going any further make sure to run the command and test it so you can keep up with this tutorial.

Filesystem             1K-blocks     Used Available Use% Mounted on
/dev/sda2              476482584 31790184 420481764   8% /
udev                     1951928        4   1951924   1% /dev
tmpfs                     785960      860    785100   1% /run
none                        5120        0      5120   0% /run/lock
none                     1964892      276   1964616   1% /run/shm
/dev/sda1                  94759     2099     92660   3% /boot/efi
/home/oltjano/.Private 476482584 31790184 420481764   8% /home/oltjano

The information given by the df tool when it is called without any arguments is oraganised in six different columns. We can easily gather stats about the total space available on the file system, used space and free space.

What about the first column? It shows the disk partition as it appears in the /dev directory. Math geeks will  be very happy  to get the used space percentage.

A thing that really deserves attention and should be explained is the 1K-blocks which is used as the unit measure for expressing the used and free space. The block size is 1024 bytes.

We didn’t say anything about the last column, did we? Are you curious to know something about the information it holds? The final column gives information about the mounting point of each one of the file systems.

Note: The / indicates the root partition.

Now lets make the displayed information available in an easy format so humans can understand it. To do this we need to call df with the h option which will print sizes in a human readable format.

df -h

The above command produces the following output.

Filesystem              Size  Used Avail Use% Mounted on
/dev/sda2               455G   31G  402G   8% /
udev                    1.9G  4.0K  1.9G   1% /dev
tmpfs                   768M  860K  767M   1% /run
none                    5.0M     0  5.0M   0% /run/lock
none                    1.9G  276K  1.9G   1% /run/shm
/dev/sda1                93M  2.1M   91M   3% /boot/efi
/home/oltjano/.Private  455G   31G  402G   8% /home/oltjano

It is easier to understand and interpret it now, isn’t it? Maybe you are interested in a grant total. The total option can be used to help you with that.

df --total

The following is the output of the above command.

Filesystem             1K-blocks     Used Available Use% Mounted on
/dev/sda2              476482584 31790820 420481128   8% /
udev                     1951928        4   1951924   1% /dev
tmpfs                     785960      860    785100   1% /run
none                        5120        0      5120   0% /run/lock
none                     1964892      276   1964616   1% /run/shm
/dev/sda1                  94759     2099     92660   3% /boot/efi
/home/oltjano/.Private 476482584 31790820 420481128   8% /home/oltjano
total                  957767827 63584879 845761676   7%

You can also scale sizes before printing them. According to the man page of the df command, when the utility is invoked with the  -BM option it prints sizes in units of 1,048,576 bytes.

And now the last but not least, the -i option. It is used to display information about the inodes that are available on a file system. Each file system has a specified number of inodes.

What does the term inode mean?

As far as I am concerned it is used to represent a file system object.

When asked, Unix pioneer Dennis Ritchie replied:

In truth, I don’t know either. It was just a term that we started to use. “Index” is my best guess, because of the slightly unusual file system structure that stored the access information of files as a flat array on the disk, with all the hierarchical directory information living aside from this. Thus the i-number is an index in this array, the i-node is the selected element of the array. (The “i-“ notation was used in the 1st edition manual; its hyphen was gradually dropped.)

Ok, now run the following command and see what is going to happen.

df -i

The following is the information that gets displayed in my lovely terminal.

Filesystem               Inodes  IUsed    IFree IUse% Mounted on
/dev/sda2              30269440 440465 29828975    2% /
udev                     487982    513   487469    1% /dev
tmpfs                    491223    443   490780    1% /run
none                     491223      3   491220    1% /run/lock
none                     491223      9   491214    1% /run/shm
/dev/sda1                     0      0        0     - /boot/efi
/home/oltjano/.Private 30269440 440465 29828975    2% /home/oltjano

Go hard in terminal and play hard!

For more information, refer the man pages.

man df