du -ah Command in Linux
When managing a Linux server, knowing which files and directories are consuming storage is important. The du -ah command provides a simple way to view disk usage for both files and directories in a human-readable format.
The current Solace Infotech page describes du -ah as a way to find large files and monitor disk space.
What Does du -ah Mean?
The command is:
du -ah
Here:
dumeans disk usage.-adisplays usage for files as well as directories.-hdisplays sizes in a human-readable format such as KB, MB, and GB.
For example:
4.0K ./test.txt
20M ./images
150M ./backup
This makes it easier to understand where storage is being used.
Check a Specific Directory
You can run the command against a particular location:
du -ah /var/log
This can help identify large log files or directories consuming excessive disk space.
Find Large Files
Combining du with sort can make it easier to find the largest items:
du -ah /var | sort -h
The result can help you quickly identify which files or directories require attention.
du -ah vs df -h
These commands are often used together.
df -h shows overall filesystem space.
du -ah shows where that space is being consumed.
For example, use df -h when you want to know whether a disk is nearly full, and du -ah when you want to investigate what is using the storage.
Best Practices
Use du -ah when troubleshooting disk-space problems, but avoid running it on very large directory trees without a specific purpose because the output can become extensive.
Before deleting large files, always verify that they are unnecessary and not required by the operating system or an application.
Conclusion
The du -ah command is a useful Linux tool for understanding disk usage at both the file and directory level. Its combination of detailed output and human-readable sizes makes it especially helpful for server monitoring and troubleshooting.
For practical Linux administration, combining df -h with du -ah provides a useful way to understand both how much storage is available and where it is being used.