We use the df command to find the type of file systems, free and used space on them, where these file systems are mounted, among others.
Table of Contents
- Basic application of df in Linux
- How to get the file system space in 1m-blocks using df in Linux
- How to get the file system space in human readable form using df in Linux
- How to display all file systems
- How to know the file system type in Linux using df
- How to print only a certain type of file system in the df command
- How to exclude a certain type of file system from the df command
- How to get only the desired columns in the df command
- How to limit listing to local file systems
- Wrapping up
Basic application of df in Linux
The df command stands for disk free. That means it is mainly used to know the free space.
By default, if no argument is given, the df command shows the information about all the mounted file system. For example:
~$ df
Output:
Filesystem 1K-blocks Used Available Use% Mounted on
dev 3452072 0 3452072 0% /dev
run 3493196 1316 3491880 1% /run
/dev/nvme0n1p5 163181380 78961860 75857536 52% /
tmpfs 3493196 30600 3462596 1% /dev/shm
/dev/nvme1n1p1 479596204 278631560 176528984 62% /mnt/crucial
tmpfs 3493200 268 3492932 1% /tmp
tmpfs 698636 1644 696992 1% /run/user/1000
The ‘1K-blocks’ column shows the total size in 1K blocks. The columns ‘Used’ and ‘Available’ show used and available space on the file system. ‘Use%’ shows the percentage of space that has been filled up. The Mounted on
column shows where the file system is mounted.
When you use the df command with a file(s) or folder(s) as its argument, it will give you the information only about those file systems on which the file(s)/folder(s) are located. For example, the directory /mnt/crucial/backup is located on the file system /dev/nvme1n1p1 and hence all other file systems are not outputted.
~$ df /mnt/crucial/backup
Output:
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/nvme1n1p1 479596204 278631560 176528984 62% /mnt/crucial
How to get the file system space in 1m-blocks using df in Linux
To print the columns in multiples of 1024 (i.e. 1M-blocks) instead of the default 1K-blocks, use the flag -m.
~$ df -m
Output:
Filesystem 1M-blocks Used Available Use% Mounted on
dev 3372 0 3372 0% /dev
run 3412 2 3411 1% /run
/dev/nvme0n1p5 159357 77112 74080 52% /
tmpfs 3412 26 3386 1% /dev/shm
/dev/nvme1n1p1 468356 272102 172392 62% /mnt/crucial
tmpfs 3412 1 3412 1% /tmp
tmpfs 683 2 681 1% /run/user/1000
How to get the file system space in human readable form using df in Linux
You need to use --human-readable
or -h
. This way, df will automatically choose the appropriate unit from the K, M, and G.
By the way, I prefer the GNU syntax (i.e. --human-readable
) over the Unix syntax (i.e. -h) because it is easier to remember and stays in the mind for a longer time.
~$ df --human-readable
Output:
Filesystem Size Used Avail Use% Mounted on
dev 3.3G 0 3.3G 0% /dev
run 3.4G 1.3M 3.4G 1% /run
/dev/nvme0n1p5 156G 76G 73G 52% /
tmpfs 3.4G 15M 3.4G 1% /dev/shm
/dev/nvme1n1p1 458G 266G 169G 62% /mnt/crucial
tmpfs 3.4G 268K 3.4G 1% /tmp
tmpfs 683M 908K 682M 1% /run/user/1000
The above output is somewhat similar to that in gnome-system-monitor. So, if you prefer GUI apps, you can use that as well.
The above units (K, M, and G) are multiples of 1024. To make them multiple of 1000 instead, use the flag --si
or -H
.
[ajay@lenovo ~]$ df --si
Output:
Filesystem Size Used Avail Use% Mounted on
dev 3.6G 0 3.6G 0% /dev
run 3.6G 1.4M 3.6G 1% /run
/dev/nvme0n1p5 168G 84G 76G 53% /
tmpfs 3.6G 7.4M 3.6G 1% /dev/shm
/dev/nvme1n1p1 492G 288G 179G 62% /mnt/crucial
tmpfs 3.6G 25k 3.6G 1% /tmp
tmpfs 716M 107k 716M 1% /run/user/1000
How to display all file systems
To display all file systems, you need to use --all
or -a
flag. Now, all the filesystems including pseudo, duplicate, inaccessible ones will be printed out.
~$ df --all
Output:
Filesystem 1K-blocks Used Available Use% Mounted on
proc 0 0 0 - /proc
sys 0 0 0 - /sys
dev 3452072 0 3452072 0% /dev
run 3493196 1316 3491880 1% /run
efivarfs 0 0 0 - /sys/firmware/efi/efivars
/dev/nvme0n1p5 163181380 78961808 75857588 52% /
securityfs 0 0 0 - /sys/kernel/security
tmpfs 3493196 26500 3466696 1% /dev/shm
devpts 0 0 0 - /dev/pts
cgroup2 0 0 0 - /sys/fs/cgroup
pstore 0 0 0 - /sys/fs/pstore
bpf 0 0 0 - /sys/fs/bpf
systemd-1 0 0 0 - /proc/sys/fs/binfmt_misc
mqueue 0 0 0 - /dev/mqueue
hugetlbfs 0 0 0 - /dev/hugepages
debugfs 0 0 0 - /sys/kernel/debug
tracefs 0 0 0 - /sys/kernel/tracing
configfs 0 0 0 - /sys/kernel/config
fusectl 0 0 0 - /sys/fs/fuse/connections
/dev/nvme1n1p1 479596204 278631560 176528984 62% /mnt/crucial
tmpfs 3493200 268 3492932 1% /tmp
tmpfs 698636 1344 697292 1% /run/user/1000
gvfsd-fuse 0 0 0 - /run/user/1000/gvfs
How to know the file system type in Linux using df
To know whether the file system is mounted as ext4, NTFS, etc. you need to use --print-type
or -T
. Consequently, an extra column ‘Type’ will be printed out as well.
~$ df --print-type
Output:
Filesystem Type 1K-blocks Used Available Use% Mounted on
dev devtmpfs 3452072 0 3452072 0% /dev
run tmpfs 3493196 1316 3491880 1% /run
/dev/nvme0n1p5 ext4 163181380 78961828 75857568 52% /
tmpfs tmpfs 3493196 26500 3466696 1% /dev/shm
/dev/nvme1n1p1 ext4 479596204 278631560 176528984 62% /mnt/crucial
tmpfs tmpfs 3493200 268 3492932 1% /tmp
tmpfs tmpfs 698636 1464 697172 1% /run/user/1000
How to print only a certain type of file system in the df command
For this, you need to use --type
or -t
flag.
For example, in order to print only the ext4 type of file system, we will use the following command:
~$ df --type=ext4
Output:
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/nvme0n1p5 163181380 78961828 75857568 52% /
/dev/nvme1n1p1 479596204 278631560 176528984 62% /mnt/crucial
How to exclude a certain type of file system from the df command
Use --exclude-type
or -x
to exclude unwanted file systems.
For example, to exclude, the ext4 file system, we use the following command:
~$ df --exclude-type=ext4
Output:
Filesystem 1K-blocks Used Available Use% Mounted on
dev 3452072 0 3452072 0% /dev
run 3493196 1316 3491880 1% /run
tmpfs 3493196 26500 3466696 1% /dev/shm
tmpfs 3493200 268 3492932 1% /tmp
tmpfs 698636 1584 697052 1% /run/user/1000
How to get only the desired columns in the df command
The above commands give a lot of columns which are not good if you are writing the scripts such as those for i3blocks, dwmblocks, etc. To get only the limited set of columns (called “fields”), use the flag --output
.
~$ df --output=field1,field2,...
Valid field names are:
‘source’ (source of the mount point, ex – /dev/sda1),
‘fstype’ (file system type, ex – ext4),
‘itotal’ (total number of inodes),
‘iused’ (number of used inodes),
‘iavail’ (number of available inodes),
‘ipcent’ (percentage of inodes which have been used),
‘size’ (total size),
‘used’ (used space),
‘avail’ (available space),
‘pcent’ (used percentage),
‘file’ (file name if specified on the command line, ex – for the example shown below, it is /mnt/crucial), and
‘target’ (mount location).
For example, to get only the space available on the SSD, mounted at /mnt/crucial/, I use the following command in my i3blocks:
[ajay@lenovo ~]$ df --output=size /mnt/crucial
Output:
1K-blocks
479596204
Another Example:
[ajay@lenovo ~]$ df --output=fstype,size,target
Output:
Type 1K-blocks Mounted on
devtmpfs 3452072 /dev
tmpfs 3493196 /run
ext4 163181380 /
tmpfs 3493196 /dev/shm
ext4 479596204 /mnt/crucial
tmpfs 3493200 /tmp
tmpfs 698636 /run/user/1000
How to limit listing to local file systems
Syntax:
~$ df --local
Wrapping up
That’s all folks. One more point to note is that the above flags can be mixed to create new commands (for example, df --human-readable --print-type
). If you want (TUI) version of disk space manager, look at our article on Ncdu.
Thank you for staying so long. If there are any mistakes, suggestions, or you have problems, please comment below.