ZetCode

Linux df Command

last modified October 23, 2026

The df (disk free) command in Linux reports the size, used space, and available space of mounted file systems. It answers the question of how full a disk or partition is. To find out which directories take up the space, use the du command.

The examples were run on a laptop with an NVMe disk that has an ext4 root partition and a small EFI system partition, plus several in-memory tmpfs file systems. They use GNU df from coreutils.

Basic usage

Without arguments, df lists all mounted file systems.

df

The columns show the device or file system name, the size in 1K blocks, the used and available space, the usage percentage, and the mount point. On ext4, Used and Available do not add up to the size, because about 5% of the blocks are reserved for root by default; the percentage is computed from the space available to regular users.

$ df
Filesystem     1K-blocks      Used Available Use% Mounted on
tmpfs            1616600      2088   1614512   1% /run
/dev/nvme0n1p2 479079112 385077316  69592404  85% /
tmpfs            8082988     65392   8017596   1% /dev/shm
tmpfs               5120         4      5116   1% /run/lock
efivarfs             184       181         0 100% /sys/firmware/efi/efivars
/dev/nvme0n1p1    523248      6232    517016   2% /boot/efi
tmpfs            1616596       124   1616472   1% /run/user/1000

Human-readable sizes

The -h option prints sizes with units, using powers of 1024. The -H option uses powers of 1000.

df -h
df -H /

-h is the usual choice for reading. Disk manufacturers use powers of 1000, which is why -H reports a larger size for the same partition, closer to the capacity printed on the label.

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           1.6G  2.1M  1.6G   1% /run
/dev/nvme0n1p2  457G  368G   67G  85% /
tmpfs           7.8G   64M  7.7G   1% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
efivarfs        184K  181K     0 100% /sys/firmware/efi/efivars
/dev/nvme0n1p1  511M  6.1M  505M   2% /boot/efi
tmpfs           1.6G  124K  1.6G   1% /run/user/1000
$ df -H /
Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p2  491G  395G   72G  85% /

File system of a path

Given a file or directory, df shows the file system it resides on.

df -h /home/jano
df -h .
df -h /boot/efi

The home directory is on the root partition here, as is the current directory. This is the quickest way to find out how much space is left where we want to write a file.

$ df -h /home/jano
Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p2  457G  368G   67G  85% /
$ df -h .
Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p2  457G  368G   67G  85% /
$ df -h /boot/efi
Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p1  511M  6.1M  505M   2% /boot/efi

File system types

The -T option adds the file system type. The -t option shows only the given types, and -x excludes them.

df -hT
df -h -t ext4
df -h -x tmpfs -x efivarfs

Excluding virtual file systems such as tmpfs leaves only the real disk partitions. Both options can be repeated.

$ df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
tmpfs          tmpfs     1.6G  2.1M  1.6G   1% /run
/dev/nvme0n1p2 ext4      457G  368G   67G  85% /
tmpfs          tmpfs     7.8G   64M  7.7G   1% /dev/shm
tmpfs          tmpfs     5.0M  4.0K  5.0M   1% /run/lock
efivarfs       efivarfs  184K  181K     0 100% /sys/firmware/efi/efivars
/dev/nvme0n1p1 vfat      511M  6.1M  505M   2% /boot/efi
tmpfs          tmpfs     1.6G  124K  1.6G   1% /run/user/1000
$ df -h -t ext4
Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p2  457G  368G   67G  85% /
$ df -h -x tmpfs -x efivarfs
Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p2  457G  368G   67G  85% /
/dev/nvme0n1p1  511M  6.1M  505M   2% /boot/efi

Inode usage

The -i option reports inodes instead of blocks. Each file and directory needs one inode.

df -i /
df -hi -t ext4 -t vfat

A file system can run out of inodes while it still has free space, typically when it holds millions of small files; then no new files can be created. The FAT file system of the EFI partition has no inodes, so it reports zeros.

$ df -i /
Filesystem       Inodes   IUsed    IFree IUse% Mounted on
/dev/nvme0n1p2 30498816 3627411 26871405   12% /
$ df -hi -t ext4 -t vfat
Filesystem     Inodes IUsed IFree IUse% Mounted on
/dev/nvme0n1p2    30M  3.5M   26M   12% /
/dev/nvme0n1p1      0     0     0     - /boot/efi

Total

The --total option adds a line with the sums.

df -h --total -x tmpfs -x efivarfs

The total combines the listed file systems, here the root and EFI partitions.

$ df -h --total -x tmpfs -x efivarfs
Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p2  457G  368G   67G  85% /
/dev/nvme0n1p1  511M  6.1M  505M   2% /boot/efi
total           458G  368G   67G  85% -

Selecting columns

The --output option selects and orders the columns.

df -h --output=source,fstype,size,used,avail,pcent,target -x tmpfs
df --output=pcent / | tail -n 1

The available fields include source, fstype, itotal, iused, size, used, avail, pcent, and target. A single field is convenient in scripts.

$ df -h --output=source,fstype,size,used,avail,pcent,target -x tmpfs
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/nvme0n1p2 ext4      457G  368G   67G  85% /
efivarfs       efivarfs  184K  181K     0 100% /sys/firmware/efi/efivars
/dev/nvme0n1p1 vfat      511M  6.1M  505M   2% /boot/efi
$ df --output=pcent / | tail -n 1
 85%

Sorting by usage

The output can be sorted with sort.

df -h | tail -n +2 | sort -k5 -rn

The tail command removes the header line, and sort orders the file systems by the fifth column, the usage percentage, from the fullest. The efivarfs file system, which stores firmware variables, always appears full.

$ df -h | tail -n +2 | sort -k5 -rn
efivarfs        184K  181K     0 100% /sys/firmware/efi/efivars
/dev/nvme0n1p2  457G  368G   67G  85% /
/dev/nvme0n1p1  511M  6.1M  505M   2% /boot/efi
tmpfs           7.8G   64M  7.7G   1% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           1.6G  2.1M  1.6G   1% /run
tmpfs           1.6G  124K  1.6G   1% /run/user/1000

Checking a threshold

In monitoring scripts, df is used to warn when a file system is almost full.

df -h -x tmpfs -x efivarfs | awk 'NR > 1 && $5+0 >= 80 {print $6 " is " $5 " full"}'
usage=$(df --output=pcent / | tail -n 1 | tr -dc '0-9'); echo "root usage: $usage%"

In awk, adding 0 to 85% turns it into the number 85. The second command extracts the bare number for use in shell conditions, for example [ "$usage" -ge 90 ].

$ df -h -x tmpfs -x efivarfs | awk 'NR > 1 && $5+0 >= 80 {print $6 " is " $5 " full"}'
/ is 85% full
$ usage=$(df --output=pcent / | tail -n 1 | tr -dc '0-9'); echo "root usage: $usage%"
root usage: 85%

df and du disagree

Sometimes df reports much more used space than du finds in the files. The usual cause is a deleted file that a running process still keeps open, such as a log file removed while the service writes to it. The space is freed only when the process closes the file; lsof +L1 lists such files. Reserved blocks and files hidden under a mount point also contribute to the difference.

Best practices for df

Source

GNU df manual

In this article, we have used the df command to report disk space and inode usage, filter file system types, select columns, and check usage thresholds in scripts.

Author

My name is Jan Bodnar, and I am a passionate programmer with extensive programming experience. I have been writing programming articles since 2007. To date, I have authored over 1,400 articles and 8 e-books. I possess more than ten years of experience in teaching programming.

List all Linux tutorials.