
How to Use the df Command for Disk Space Management
Understanding the df
Command: A Comprehensive Guide
The df
command is a vital utility in Unix and Unix-like operating systems that provides an overview of filesystem disk space usage. This command is essential for system administrators and users who need to manage their system’s storage efficiently.
Overview of df
When executed, df
displays information about the total space, used space, available space, and the mount points of all filesystems. This information helps users quickly identify how much disk space is being utilized and how much is still free.
For detailed information, you can refer to the official GNU documentation here.
Basic Usage
Display All Filesystems
To view the disk usage of all filesystems, simply use the following command:
df
This command will list all mounted filesystems along with their usage statistics.
Human-Readable Format
To make the output more understandable, especially on systems with large capacities, use the -h
option:
df -h
This format displays sizes in human-readable form (e.g., KB, MB, GB), making it easier to parse quickly.
Check Disk Usage for Specific Files or Directories
If you want to see the disk usage for a specific file or directory, you can specify its path:
df path/to/file_or_directory
This will display the filesystem containing the specified file or directory, along with its usage statistics.
Inode Statistics
Inodes are data structures used to store information about files. To include statistics on the number of free inodes, use the -i
option:
df -i
This output will show the total inodes, used inodes, and free inodes for each filesystem.
Exclude Specific Filesystem Types
You may want to exclude certain filesystem types, such as squashfs
or tmpfs
, from the output. You can do this with the -x
option:
df -x squashfs -x tmpfs
This command will display all filesystems except the specified types.
Display Filesystem Types
To display the types of filesystems along with their usage, you can use the -T
option:
df -T
This will provide a summary of each filesystem’s usage alongside its type, which can be useful for troubleshooting and understanding your system’s configuration.
Conclusion
The df
command is an invaluable tool for monitoring disk space usage on Unix and Linux systems. By understanding its various options, you can effectively manage storage and ensure your system runs smoothly. Whether you’re checking overall disk usage or looking into specific filesystem metrics, the df
command provides essential insights for system management.