Df command tutorial with examples for beginners

In this tutorial, we will learn to use the df command. Df command means Disk Free, which means the use of disk space on the file system. It displays the amount of disk space available on the file system on a Linux system. The DF command should not be confused with the df command. They serve a variety of purposes. DF team reports, how much disk space do we have (i.e. free space), whereas df command reports, it is how much disk space is consumed to files and folders. Hope we have explained to you clearly. Let’s go ahead and see some practical examples of the df command so that you can understand it better. Df command tutorial with examples

1. Kind of using the entire file system on disk

Run the commands without any arguments to display the entire disk space of the file system.

$ df

Output example:

Filesystem 1K-blocks Used Available Use% Mounted on
dev 4033216 0 4033216 0% /dev
run 4038880 1120 4037760 1% /run
/dev/sda2 478425016 428790352 25308980 95% /
tmpfs 4038880 34396 4004484 1% /dev/shm
tmpfs 4038880 0 4038880 0% /sys/fs/cgroup
tmpfs 4038880 11636 4027244 1% /tmp
/dev/loop0 84096 84096 0 100% /var/lib/snapd/snap/core/4327
/dev/sda1 95054 55724 32162 64% /boot
tmpfs 807776 28 807748 1% /run/user/1000

As you can see, the result is divided into six columns. Let’s see what each column means.

  • Filesystem – file system in the system.
  • 1K-blocks – file system size, measured in 1K blocks.
  • Used – the amount of used space in 1K blocks.
  • Available – the amount of free space in 1K blocks.
  • Use% – percentage of filesystem usage.
  • Mounted on Is the mount point where the filesystem is installed.

2. Using the file system of the disk. Display in human readable format

As you can see in the examples above, usage is shown in 1k blocks. If you want to display them in a human readable format, use the flag -h

$ df -h
Filesystem Size Used Avail Use% Mounted on
dev 3.9G 0 3.9G 0% /dev
run 3.9G 1.1M 3.9G 1% /run
/dev/sda2 457G 409G 25G 95% /
tmpfs 3.9G 27M 3.9G 1% /dev/shm
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
tmpfs 3.9G 12M 3.9G 1% /tmp
/dev/loop0 83M 83M 0 100% /var/lib/snapd/snap/core/4327
/dev/sda1 93M 55M 32M 64% /boot
tmpfs 789M 28K 789M 1% /run/user/1000

Now let’s look at the columns Size and Avail, usage is shown in GB and MB.

3. Show disk space usage in MB only

To view the disk space usage in the file system only in megabytes, use the flag -m

$ df -m
Filesystem 1M-blocks Used Available Use% Mounted on
dev 3939 0 3939 0% /dev
run 3945 2 3944 1% /run
/dev/sda2 467212 418742 24716 95% /
tmpfs 3945 26 3920 1% /dev/shm
tmpfs 3945 0 3945 0% /sys/fs/cgroup
tmpfs 3945 12 3933 1% /tmp
/dev/loop0 83 83 0 100% /var/lib/snapd/snap/core/4327
/dev/sda1 93 55 32 64% /boot
tmpfs 789 1 789 1% /run/user/1000

4. Listing inode information instead of using a block

We can list information inode instead of using a block with a flag -ias shown below.

$ df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
dev 1008304 439 1007865 1% /dev
run 1009720 649 1009071 1% /run
/dev/sda2 30392320 844035 29548285 3% /
tmpfs 1009720 86 1009634 1% /dev/shm
tmpfs 1009720 18 1009702 1% /sys/fs/cgroup
tmpfs 1009720 3008 1006712 1% /tmp
/dev/loop0 12829 12829 0 100% /var/lib/snapd/snap/core/4327
/dev/sda1 25688 390 25298 2% /boot
tmpfs 1009720 29 1009691 1% /run/user/1000

5. Displaying the file system type

To display the type of filesystem, use the flag -T

$ df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
dev devtmpfs 4033216 0 4033216 0% /dev
run tmpfs 4038880 1120 4037760 1% /run
/dev/sda2 ext4 478425016 428790896 25308436 95% /
tmpfs tmpfs 4038880 31300 4007580 1% /dev/shm
tmpfs tmpfs 4038880 0 4038880 0% /sys/fs/cgroup
tmpfs tmpfs 4038880 11984 4026896 1% /tmp
/dev/loop0 squashfs 84096 84096 0 100% /var/lib/snapd/snap/core/4327
/dev/sda1 ext4 95054 55724 32162 64% /boot
tmpfs tmpfs 807776 28 807748 1% /run/user/1000

As you can see, there is an additional column (second from the left) that shows the type of filesystem.

6. Display only a specific type of file system

We can limit the list to specific filesystems. eg, ext4… For this we use the flag -t

$ df -t ext4
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 478425016 428790896 25308436 95% /
/dev/sda1 95054 55724 32162 64% /boot

Did you see? This command only shows the disk space usage of the ext4 filesystem.

7. Exclude a specific type of filesystem

You can exclude a specific filesystem from the result. This can be achieved by using a flag -x

$ df -x ext4
Filesystem 1K-blocks Used Available Use% Mounted on
dev 4033216 0 4033216 0% /dev
run 4038880 1120 4037760 1% /run
tmpfs 4038880 26116 4012764 1% /dev/shm
tmpfs 4038880 0 4038880 0% /sys/fs/cgroup
tmpfs 4038880 11984 4026896 1% /tmp
/dev/loop0 84096 84096 0 100% /var/lib/snapd/snap/core/4327
tmpfs 807776 28 807748 1% /run/user/1000

This command will show the use of all filesystems except ext4

8. Show usage for folders

To display the available disk space and where it is connected to a folder, for example / home / sk /, use the following command:

$ df -hT /home/sk/
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda2 ext4 457G 409G 25G 95% /

This command shows the file system type, used and available space in a readable form and where it is installed. If you don’t want to display the filesystem type, just ignore with the flag -t

See the man page for more details.

$ man df

Df command tutorial with examples for beginners

Sidebar