Welcome to this lesson on Disk Usage Monitoring. Keeping track of disk usage is essential for maintaining system health and ensuring that there is adequate storage space for applications and data. Monitoring disk usage helps system administrators detect potential issues early, avoid system crashes, and maintain optimal system performance.
Let's dive in!
The df command provides statistics about certain filesystems. If you want to estimate the disk usage of files and directories we can use the du command. The -h option is used to provide a human-readable report of the disk usage for all files and directories within the specified directory. It lists each item along with its size in human-readable format.
The -sh option provides a summary of the total disk usage for the specified directory in human-readable format. It does not list individual items. Instead, it gives you the total disk usage of the entire directory at the top level.
Let's take a look at the disk usage of our $FILESYSTEM directory.
The output is:
Let's look at the output of du -h $FILESYSTEM
12K /usercode/FILESYSTEM/.codesignal: This indicates that the.codesignaldirectory inside /usercode/FILESYSTEMis using 12 KB of disk space.20K /usercode/FILESYSTEM: This indicates that the total disk usage of the/usercode/FILESYSTEMdirectory is 20 KB, which includes the space used by its contents (like the.codesignaldirectory).
The output of the du -sh $FILESYSTEM command is: 20K /usercode/FILESYSTEM.
This is a summarized report indicating that the total disk usage of the entire /usercode/FILESYSTEM directory is 20 KB. It does not provide a breakdown of individual files or subdirectories.
Excellent work! You've now learned how to:
- Use the
dfcommand to monitor disk space usage of filesystems. - Utilize the
-hoption withdfto present information in a human-readable format. - Use the
ducommand to estimate disk usage of files and directories. - Employ the
-hand-shoptions withduto provide detailed and summarized reports. - Create and manage large files using the
fallocatecommand to understand their impact on disk usage.
By mastering these commands, you can quickly identify disk usage issues and take appropriate actions to resolve them. This knowledge is essential for maintaining system stability and performance. Now that you've gained a solid understanding of disk usage monitoring, it's time to put your knowledge into practice. Head over to the practice section to apply what you've learned and continue honing your skills. Happy monitoring!
