In the Linux environment, keeping track of disk space usage is crucial for effective resource management. Two of the most commonly used tools for this task are df and du. These commands provide valuable information about disk space usage, and understanding how to interpret their output is essential for any user or system administrator. In this post, we will explore how to use these commands, with a special focus on their "human-readable" (-h) versions.
Get the most out of your project with the fastest disks and most powerful CPUs in the Cloud.
df commandThe df (disk free) command is used to get a report of the total, used and available space on mounted file systems. To make the output more readable, you can use the -h (human-readable) option, which displays sizes in more understandable units (KB, MB, GB).
Basic Syntax:
df -h
Typical Exit:
| Filesystem | Size | Used | Avail | Use% | Mounted on |
|---|---|---|---|---|---|
| udev | 7.8G | 0 | 7.8G | 0% | /dev |
| tmpfs | 881M | 788K | 880M | 1% | /run |
| /dev/xvda3 | 28G | 19G | 7.2G | 73% | / |
| tmpfs | 4.3G | 0 | 4.3G | 0% | /dev/shm |
| tmpfs | 5.0M | 0 | 5.0M | 0% | /run/lock |
| tmpfs | 4.0G | 9.6M | 4.0G | 1% | /tmp |
| /dev/xvda1 | 447M | 57M | 362M | 14% | /boot |
| tmpfs | 881M | 0 | 881M | 0% | /run/user/0 |
Explanation of Columns:
Our Hosting gives you the freedom to tailor your website to your brand and goals.
du commandUnlike df, the du (disk usage) command is used to estimate the disk space usage of the specified file or directory. Like df, du can use the -h option to display the information in human-readable format.
Basic Syntax:
du -h /path/to/directory
Typical Exit:
| Size | Directory |
|---|---|
| 1.5M | /home/user/Documents |
| 500K | /home/user/Downloads |
Exit Explanation:
What to look for?
df, look for mount points near 100% usage, as this indicates that they are nearly full.du, identify directories that take up an unusually large amount of space, which might suggest a need for cleanup or reorganisation.Additional Tips:
For further analysis, du can be combined with other commands such as sort to sort directories by size:
du -h | sort -h
Use df regularly to monitor filesystems, especially in production environments where free space is critical.
In summary, df and du are powerful tools for disk space management in Linux. Knowing how to correctly interpret their output can help prevent space problems and keep your system running smoothly.
A domain name is the first step to make your project a reality. Enjoy the best domain rates.