Introduction
Disk space management is a critical aspect of system administration in Linux environments. Monitoring available disk space helps prevent system crashes, application failures, and data loss that can occur when storage resources are depleted. As a system administrator, one of your routine tasks is checking disk space utilization across different filesystems.
In this lab, you will learn how to use the powerful df command (which stands for "disk free") to check disk space usage across your system. You will examine disk usage for all mounted filesystems, interpret the output, and focus on specific directories to gain deeper insights into your storage utilization. These skills are essential for effective system maintenance and resource planning.
Check Basic Disk Space Usage
In this step, you will learn how to check the disk space usage across all mounted filesystems using the df command. The df command is a fundamental tool for displaying the amount of disk space available on the file system.
Open a terminal in your LabEx VM environment. By default, you should already be in the home directory. If not, you can navigate there with:
cd ~
Now, run the following command to check disk space usage:
df
You will see output similar to this:
Filesystem 1K-blocks Used Available Use% Mounted on
overlay 20509264 3207552 16249328 17% /
tmpfs 395052 0 395052 0% /dev
tmpfs 1975244 0 1975244 0% /sys/fs/cgroup
shm 65536 0 65536 0% /dev/shm
/dev/sda1 20509264 3207552 16249328 17% /etc/hosts
tmpfs 1975244 0 1975244 0% /proc/acpi
tmpfs 1975244 0 1975244 0% /sys/firmware
The output shows you several important pieces of information for each filesystem:
Filesystem: The name of the filesystem1K-blocks: The total size in 1 kilobyte blocksUsed: How much space is currently being usedAvailable: How much space is available for useUse%: The percentage of space that is being usedMounted on: The mount point of the filesystem
While this information is comprehensive, the numbers in 1K blocks can be difficult to read and interpret quickly.
Using Human-Readable Format
When working with disk space information, it is often easier to interpret the data when it is presented in a more readable format. In this step, you will learn how to use the -h flag with the df command to display sizes in a human-readable format.
The -h option (which stands for "human-readable") converts the disk space numbers into a format that uses appropriate units (KB, MB, GB, or TB) based on the size. This makes the output much easier to understand at a glance.
Run the following command in your terminal:
df -h
You should see output similar to this:
Filesystem Size Used Avail Use% Mounted on
overlay 20G 3.1G 16G 17% /
tmpfs 386M 0 386M 0% /dev
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
shm 64M 0 64M 0% /dev/shm
/dev/sda1 20G 3.1G 16G 17% /etc/hosts
tmpfs 1.9G 0 1.9G 0% /proc/acpi
tmpfs 1.9G 0 1.9G 0% /sys/firmware
Notice how the disk space is now displayed in GB and MB instead of 1K blocks. This makes it much easier to quickly understand how much space is being used and how much is available.
Compare this output with the output from Step 1. You can see that the information is the same, but the presentation is much more intuitive with the -h option. For example, instead of seeing "20509264" 1K-blocks, you now see "20G" (20 gigabytes), which is much easier to comprehend.
Analyzing Specific Filesystem or Directory
Sometimes, you only need information about a specific filesystem or directory. In this step, you will learn how to check disk space for a particular location in your file system.
You can specify a path to the df command to get information about the filesystem where that path resides. This is particularly useful when you want to check available space before copying or downloading files to a specific location.
Let's check the disk space for your home directory. Run the following command:
df -h ~
The tilde (~) symbol is a shorthand for your home directory in Linux. The command will provide information about the filesystem containing your home directory:
Filesystem Size Used Avail Use% Mounted on
overlay 20G 3.1G 16G 17% /
This shows that your home directory is located on the root filesystem (mounted at /).
Now, let's check disk space for another directory. For example, let's look at the /tmp directory, which is often used for temporary files:
df -h /tmp
The output will show details about the filesystem where /tmp is located:
Filesystem Size Used Avail Use% Mounted on
overlay 20G 3.1G 16G 17% /
In this environment, both your home directory and /tmp are on the same filesystem. In many production systems, these might be on different filesystems for performance or security reasons.
This ability to check specific locations is very useful when you need to:
- Verify if there's enough space before downloading large files
- Troubleshoot space issues in specific parts of the filesystem
- Monitor critical directories that tend to fill up quickly
Using Additional Options with df
The df command offers several other useful options that can provide additional information or change how the output is displayed. In this step, you will explore some of these options to enhance your disk space monitoring capabilities.
Display File System Type
The -T option adds a column showing the filesystem type. This can be valuable when you need to know what type of filesystem you are working with, as different filesystem types have different features and limitations.
Run the following command:
df -hT
This combines the human-readable format (-h) with the filesystem type display (-T). You should see output similar to:
Filesystem Type Size Used Avail Use% Mounted on
overlay overlay 20G 3.1G 16G 17% /
tmpfs tmpfs 386M 0 386M 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
shm tmpfs 64M 0 64M 0% /dev/shm
/dev/sda1 ext4 20G 3.1G 16G 17% /etc/hosts
tmpfs tmpfs 1.9G 0 1.9G 0% /proc/acpi
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/firmware
Notice the new "Type" column, which shows filesystem types like "overlay", "tmpfs", and "ext4".
Display Inodes Information
Filesystems have a limited number of inodes, which are data structures that store information about files. Even if you have plenty of disk space, you can run out of inodes if you have too many small files.
Check inode usage with the -i option:
df -i
You will see output showing inode utilization:
Filesystem Inodes IUsed IFree IUse% Mounted on
overlay 1310720 106794 1203926 9% /
tmpfs 98811 1 98810 1% /dev
tmpfs 98811 16 98795 1% /sys/fs/cgroup
shm 98811 1 98810 1% /dev/shm
/dev/sda1 1310720 106794 1203926 9% /etc/hosts
tmpfs 98811 1 98810 1% /proc/acpi
tmpfs 98811 1 98810 1% /sys/firmware
The output shows:
Inodes: Total number of inodesIUsed: Number of inodes that are usedIFree: Number of free inodesIUse%: Percentage of inodes that are used
This information is particularly useful when troubleshooting situations where you have disk space available but cannot create new files because you have run out of inodes.
Combining Options
You can combine these options to get a comprehensive view. For example, to see human-readable disk space and inode usage together:
df -hi
This provides a more complete picture of your filesystem usage:
Filesystem Inodes IUsed IFree IUse% Mounted on
overlay 1.3M 107K 1.2M 9% /
tmpfs 97K 1 97K 1% /dev
tmpfs 97K 16 97K 1% /sys/fs/cgroup
shm 97K 1 97K 1% /dev/shm
/dev/sda1 1.3M 107K 1.2M 9% /etc/hosts
tmpfs 97K 1 97K 1% /proc/acpi
tmpfs 97K 1 97K 1% /sys/firmware
Summary
In this lab, you have learned how to effectively monitor and analyze disk space usage in a Linux environment using the df command. Here is a recap of what you have accomplished:
- You used the basic
dfcommand to view disk space information across all mounted filesystems. - You learned how to make the output more readable with the
-hoption, which displays sizes in human-readable format. - You focused on specific directories to analyze disk space on particular filesystems.
- You explored additional options like
-Tto display filesystem types and-ito check inode usage. - You learned how to combine options for more comprehensive filesystem analysis.
These skills are essential for system administration and maintenance tasks. Regular monitoring of disk space helps prevent system issues and ensures optimal performance. As you continue to work with Linux systems, these commands will become part of your regular toolkit for proactive system management.
For more detailed information about space usage within directories (rather than entire filesystems), you can use the complementary command du (disk usage), which provides a more granular view of how disk space is being used within directories and subdirectories.



