Every file or directory you create on your Linux system requires a certain amount of disk space. You might face a situation where you need to check the available disk space on your Linux computer and the amount of disk space used by a specific file system. Linux provides the df command-line utility to display disk space information of every file system.
In this tutorial, we will learn how to use the Linux df command to check file system disk space usage.
- A Linux computer with terminal access.
- Basic command-line interface understanding.
- Willingness to learn Linux file system structures and new commands.
Df Command in Linux
The Linux df command, also known as disk free, is used to display free and used disk space for each file system on Linux and Unix-like systems.
If you do not provide a file or directory name, then df displays free and used space on all file systems that are currently mounted. Unmounted file systems are not included in the df command output. Otherwise, if you provide filename or directory as an argument, then displays disk usage of the filesystem it belongs.
By default, the Linux df command displays the free space information in 1 K blocks, which means 1024 bytes multiplied by the displayed number. For example, if the displayed free disk space value is 1976640, then it will be 1976640/1024 = 1930.3125 MB and 1930.125/1024 = 1.88 GB rounded off to 1.9 GB.
Df provides a complete picture of disk usage of a file system whereas the du command displays more exact space utilization of a given directory and its subdirectories.
The basic syntax of the df command is:
df [options] [file_path]
Df Command Options
The df command in Linux provides various options to display space information of currently mounted file systems and in different size formats. The following table lists and describes the most common df command supported options:
|To include dummy files in the output, which include zero block sizes|
|To display block size in the specified unit, such as BM for MB and BG for GB|
|To display block size in human-readable form|
|Displays inode information instead of the block usage|
|Displays disk space information of only the local file system|
|Displays file system type, such as ext4|
|Limit to showing a specific filesystem type|
|Excludes the specified file system type from the output|
How to Use Df Command
The df command in Linux can be used with or without options to display different types of disk space information. When used without any option, it displays disk space information in tabular form for all file systems in 1 K format.
The following figure describes the df command output fields:
- Filesystem is the name of the file system or disk partition.
- 1K-blocks is the total file system 1K blocks used.
- Used is the total disk space allocated to the file system.
- Available is the total free space available in the file system.
- Use% is the percentage of the used disk space in the file system.
- Mounted on is the directory on which the file system is mounted.
Depending on the display options that you specify with the df command, you might see additions fields, such as:
Type represents the specified file system type.
Inodes represent the total number of inodes in the file system.
IUsed represents the total used inodes in the file system.
IFree represents the total number of free inodes in the file system.
Iuse% represents the percentage of the used inodes in the file system.
A Linux computer has several file systems to perform different operations, which are represented as a directory tree. Use the tree command to display the list of all currently mounted file systems. For example, to display all mounted file systems in the root directory, type:
tree / -L 1
You can specify the number of levels it must display. Currently, it displays level 1 directories and files.
DF Command Examples
The following df command examples show you how to use this command to display file system disk usage information in different formats.
Check Disk Usage Information For All the File Systems
To display disk usage information for all currently mounted file systems, use the df command without any option:
Check Disk Usage Information of a Particular File System
To display disk space usage information of a specific file system, specify the file system name with the df command:
Display Disk Usage Information in Different Block Formats
By default, the disk space usage information is displayed in 1K block format. However, you can use the
-B option to display sizes information in the format of your choice. The available options are
-BM for MB,
-BG for GB, and
-BT for TB.
df -BM /boot
Display Df Output in Human Readable Form
To display the file system disk space usage information in a human-readable format that is easy to read, use the following command:
When you choose to display information in human-readable format, the command automatically displays information in the highest available space unit. Based on the size it shows in bytes, megabytes, and gigabytes.
Check File System Types
Linux supports a number of file systems, such as ext3, ext4, and squashfs. To check the type of the particular file system mounted on the /boot directory, type:
df -T /boot
If you want to display file system types for all the mounted file systems, then do not specify the directory name.
You may also limit showing specific filesystem type by:
df -T | grep -v squashfs df -T | egrep -v 'squashfs|lxcfs|udev' df -t ext4 df -t zfs df -t zfs,ext4,vfat
This tutorial describes the df command and its options. You can use this command to check disk usage and availability information for a file system on your Linux computer. This command works with all major Linux distributions, including Red Hat, Debian, Ubuntu, Fedora, and CentOS Stream. The df command does not modify the file system but just displays the usage information.