Table of Contents
It is important to check disk space regularly, because if you run out of space, you may encounter problems such as slow performance, corrupted files, or system crashes. To avoid these issues, you should always keep some free space on your disk and delete unnecessary files or folders.
One of the easiest ways to check your disk space in Linux is by using the df
command. The df command stands for disk free, and it shows you how much space is used and available on your file systems. A file system is a way of organizing and storing data on a disk. Linux supports various types of file systems, such as ext4, xfs, btrfs, etc.
In this article you are going to learn the full usage methods of df command.
Install df command
The df command is usually pre-installed on most Linux distributions, but if you don’t have it, you can install it from your package manager. For example, on Debian or Ubuntu, you can use the following command:
sudo apt install coreutils
On CentOS or Fedora, you can use:
sudo yum install coreutils
Basic Usage of df command
To run the df command without any options, just type:
df
This will display the output like this:

The output shows the following information for each file system:
- Filesystem: The name or identifier of the file system.
- 1K-blocks: The total size of the file system in 1 KB blocks.
- Used: The amount of space used by the file system in 1 KB blocks.
- Available: The amount of space available for use by the file system in 1 KB blocks.
- Use%: The percentage of space used by the file system.
- Mounted on: The mount point or location where the file system is attached to the directory tree.
The output may vary depending on your system configuration and disk layout. You can also see some special file systems that are not actually stored on disks, such as tmpfs, which is a temporary file system that resides in memory.
The default output of df command may not be very easy to read, especially if you have large numbers. To make it more human-readable, you can use the -h option, which will display the sizes in KB, MB, GB, or TB units. For example:
df -h
This will display the output like this:

As you can see, the output is much easier to understand with the -h option.
Advanced Usage of df command
The df command has many other options that can help you get more information or customize the output. Here are some of the most useful ones:
- -a: This option will include all file systems, even those that have zero size or are not mounted. This can be useful if you want to see the complete list of file systems on your system, or if you want to check the status of a file system that is not in use.
- -T: This option will display the type of each file system, such as ext4, xfs, btrfs, etc. This can be useful if you want to know what kind of file system you are dealing with, or if you want to compare the performance or features of different file systems.
- -i: This option will display the inode information for each file system. An inode is a data structure that stores the metadata of a file or directory, such as its name, size, permissions, etc. Each file system has a limited number of inodes, and if you run out of them, you will not be able to create new files or directories, even if you have enough disk space. Therefore, it is important to monitor your inode usage as well as your disk space usage.
- –output: This option will allow you to customize the output fields of the df command. You can specify which fields you want to see and in what order. For example, if you only want to see the file system name, type, and mount point, you can use:
df --output=source,fstype,target
This will display the output like this:
Filesystem Type Mounted on
/dev/root ext4 /
tmpfs tmpfs /dev/shm
tmpfs tmpfs /run
tmpfs tmpfs /run/lock
/dev/sda15 vfat /boot/efi
tmpfs tmpfs /run/user/1001
You can also combine multiple options together to get more detailed or customized output. For example, if you want to see all file systems with their type, size, and usage in human-readable format, you can use:
df -aTh
This will display the output like this:
Filesystem Type Size Used Avail Use% Mounted on
/dev/root ext4 20G 5.1G 15G 27% /
devtmpfs devtmpfs 977M 0 977M 0% /dev
proc proc 0 0 0 - /proc
sysfs sysfs 0 0 0 - /sys
securityfs securityfs 0 0 0 - /sys/kernel/security
tmpfs tmpfs 981M 0 981M 0% /dev/shm
devpts devpts 0 0 0 - /dev/pts
tmpfs tmpfs 393M 1000K 392M 1% /run
tmpfs tmpfs 5.0M 0 5.0M 0% /run/lock
cgroup2 cgroup2 0 0 0 - /sys/fs/cgroup
pstore pstore 0 0 0 - /sys/fs/pstore
efivarfs efivarfs 0 0 0 - /sys/firmware/efi/efivars
bpf bpf 0 0 0 - /sys/fs/bpf
systemd-1 - - - - - /proc/sys/fs/binfmt_misc
hugetlbfs hugetlbfs 0 0 0 - /dev/hugepages
mqueue mqueue 0 0 0 - /dev/mqueue
debugfs debugfs 0 0 0 - /sys/kernel/debug
tracefs tracefs 0 0 0 - /sys/kernel/tracing
fusectl fusectl 0 0 0 - /sys/fs/fuse/connections
configfs configfs 0 0 0 - /sys/kernel/config
ramfs ramfs 0 0 0 - /run/credentials/systemd-sysusers.service
/dev/loop0 squashfs 64M 64M 0 100% /snap/core20/1974
/dev/loop2 squashfs 112M 112M 0 100% /snap/lxd/24322
/dev/loop3 squashfs 54M 54M 0 100% /snap/snapd/19457
/dev/sda15 vfat 105M 6.1M 99M 6% /boot/efi
binfmt_misc binfmt_misc 0 0 0 - /proc/sys/fs/binfmt_misc
tmpfs tmpfs 393M 1000K 392M 1% /run/snapd/ns
nsfs nsfs 0 0 0 - /run/snapd/ns/lxd.mnt
/dev/loop5 squashfs 349M 349M 0 100% /snap/google-cloud-cli/161
/dev/loop1 squashfs 349M 349M 0 100% /snap/google-cloud-cli/163
/dev/loop4 squashfs 64M 64M 0 100% /snap/core20/2015
tmpfs tmpfs 197M 4.0K 196M 1% /run/user/1001
Filtering and Sorting the Output of df command
Sometimes, you may not want to see the entire output of df command, but only some specific file systems or results. In that case, you can use some other commands to filter or sort the output of df command. Here are some examples:
grep:
This command will allow you to search for a pattern in the output of df command. For example, if you only want to see the file systems that are mounted on /home or /var directories, you can use:
df -hT / | grep "/"
This will display the output like this:
/dev/root ext4 20G 5.1G 15G 27% /
The | symbol is used to pipe the output of one command to another command.
sort:
This command will allow you to sort the output of df command by a specific field or column. For example, if you want to sort the file systems by their usage percentage in descending order, you can use:
df -h --output=source,fstype,target,pcent | sort -n -r -k2
This will display the output like this:
tmpfs tmpfs /run/user/1001 1%
tmpfs tmpfs /run/lock 0%
tmpfs tmpfs /run 1%
tmpfs tmpfs /dev/shm 0%
Filesystem Type Mounted on Use%
/dev/sda15 vfat /boot/efi 6%
/dev/root ext4 / 27%
The -r option will reverse the order of sorting, and the -n option will sort numerically instead of alphabetically. The -k option will specify which column to sort by, in this case, the fourth one.
head or tail:
These commands will allow you to display only the first or last few lines of the output of df command. For example, if you only want to see the top three file systems with the highest usage percentage, you can use:
df -h --output=source,fstype,target,pcent | sort -nk2 | head -n3
This will display the output like this:
/dev/root ext4 / 27%
/dev/sda15 vfat /boot/efi 6%
Filesystem Type Mounted on Use%
The -n option in the head command will specify how many lines to display, in this case, three.
Using df command with Other Commands
The df command is useful for checking the disk space of your file systems, but sometimes you may want to check the disk usage of a specific directory or file, or locate large files or directories that are taking up too much space. In that case, you can use some other commands that work well with df command. Here are some examples:
du:
This command stands for disk usage, and it shows you how much space is used by a directory or file. For example, if you want to check how much space is used by your Documents directory, you can use:
du -sh /var
This will display the output like this:
2.5G /var
The -s option will summarize the total size of the directory, and the -h option will display it in human-readable format.
find:
This command will allow you to search for files or directories that match certain criteria. For example, if you want to find all files that are larger than 100 MB in your home directory, you can use:
find /var -type f -size +100M
This will display the output like this:
/var/lib/snapd/snaps/lxd_24322.snap
/var/lib/snapd/snaps/google-cloud-cli_163.snap
/var/lib/snapd/snaps/google-cloud-cli_161.snap
/var/lib/snapd/seed/snaps/lxd_24322.snap
/var/lib/snapd/seed/snaps/google-cloud-cli_157.snap
/var/lib/mysql/ib_logfile0
The -type option will specify the type of file to search for, in this case, regular files. The -size option will specify the size of file to search for, in this case, more than 100 MB.
ncdu:
This command stands for NCurses Disk Usage, and it is a graphical tool that shows you the disk usage of your directories and files in a tree-like structure. To use it, you need to install it from your package manager first. For example, on Debian or Ubuntu, you can use:
sudo apt install ncdu
On CentOS or Fedora, you can use:
sudo yum install ncdu
Then, you can run it on any directory you want to check. For example, if you want to check your home directory, you can use:
ncdu ~
This will display a graphical interface like this:


You can use the arrow keys to navigate through the directories and files, and press enter to expand or collapse them. You can also press ? to see more options and commands.
Conclusion
In this article, we have learned how to check disk space in Linux with df command. We have seen how to use different options and parameters to get more information and customize the output of df command. We have also seen how to filter and sort the output of df command with other commands such as grep, sort, head, and tail.
Finally, we have seen how to use other commands such as du, find, and ncdu to check the disk usage of specific directories or files, or locate large files or directories.
We hope you have found this article helpful and informative. If you have any questions or feedback, please feel free to leave a comment below. Thank you for reading!