On the internet, you will find plenty of tools for checking disk space usage in Linux. However, Linux has a strong built-in utility called ‘df‘.
The ‘df‘ command stands for “disk filesystem“, it is used to get a full summary of available and used disk space usage of the file system on the Linux system.
Using ‘-h
‘ parameter with (df -h) will show the file system disk space statistics in “human-readable” format, which means it gives the details in bytes, megabytes, and gigabytes.
This article explains how to get the full information on Linux disk space usage with the help of the ‘df‘ command with their practical examples. So, you could better understand the usage of the df command in Linux.
1. Check Linux Disk Space Usage
The “df
” command displays the information of device name, total blocks, total disk space, used disk space, available disk space, and mount points on a file system.
sudo df
2. Check Information on Linux Disk Space Usage
The command "df -a"
is used to display information about all the mounted filesystems disk space usage, which includes total space, used space, available space, memory utilization, and the percentage of space used for each filesystem.
It also shows pseudo filesystems with 0 blocks (those not directly tied to a physical device) and are ignored by default.
df -a
3. Show Disk Space Usage in Human Readable Format
Have you noticed that the above commands display information in bytes, which is not readable at all because we are in a habit of reading the sizes in megabytes, gigabytes, etc. as it makes it very easy to understand and remember.
The command "df -h"
is used to display disk space usage in a human-readable format. The "-h"
option stands for “human-readable” and it shows information about all mounted filesystems on your system, presenting the sizes in a format that is easier for humans to understand, using units like kilobytes (KB), megabytes (MB), gigabytes (GB), etc.
sudo df -h
4. Check Disk Space Usage of /home Directory
The command "df -hT /home"
is used to display disk space utilization of /home directory or partition in a human-readable format. The -T
option shows the filesystem type (ext4) along with other information.
df -hT /home
5. Check Disk Space Usage in Kilobytes
To display all mounted filesystem information and usage in 1024-byte blocks, use the option ‘-k
‘ (e.g. --block-size=1K
), which provides information about each filesystem on your system, presenting sizes in kilobytes (kb).
sudo df -k
6. Check Disk Space Usage in Megabytes
To display information on all file system usage in MB (MegaByte) use the option ‘-m
‘, which presents sizes in megabytes (MB).
sudo df -m
7. Check Disk Space Usage in Gigabyte
To display information on all file system statistics in GB (Gigabyte) use the command "df -h"
, which shows disk space in human-readable sizes such as kilobytes (KB), megabytes (MB), gigabytes (GB), and so on.
sudo df -h
8. Check Inode Usage in Linux
The command "df -i"
provides detailed information about the number of inodes used and available on each mounted filesystem on a Linux system. The inodes are data structures that store information about files and directories, such as ownership, permissions, and timestamps.
sudo df -i
If you find yourself in a situation where there is a shortage of inodes, you will need to increase the inode count on your Linux filesystem.
9. Check Linux File System Type
If you notice all the above commands output, you will see there is no Linux file system type mentioned in the results. To check the file system type of your system use the option ‘T
‘, which will display file system type along with other information.
sudo df -T
10. Check Disk Space Usage for ext4 Filesystems
If you want to display a certain file system type use the ‘-t
‘ option, which will display disk space usage specifically for filesystems of type ext4.
sudo df -t ext4
11. Exclude Certain File System Type
If you want to display a file system type that doesn’t belong to the ext4 type, use the option ‘-x
‘, which will print disk space usage for all mounted non-ext4 filesystem filesystems excluding those of type ext4.
sudo df -x ext4
12. Check df Command Usage
The command "df --help"
provides a list of available option that is used with the df command.
df --help
Conclusion
The ‘df‘ command is useful for checking disk space utilization on your Linux system. By running various options such as '-h'
for human-readable output or '-T'
to display filesystem types, users can obtain detailed information about the disk space usage across different mounted filesystems.