
{{ $('Map tags to IDs').item.json.title }}
Checking Disk Usage with df and du
In Linux, managing disk space is crucial for maintaining system performance and preventing outages due to full disks. The commands df
and du
are valuable tools for checking disk usage. This tutorial will guide you through using these commands effectively.
1. Understanding the df Command
The df
command (disk filesystem) provides a summary of available and used disk space on all mounted filesystems. To check disk usage, simply run:
df -h
The -h
option displays the output in a human-readable format (e.g., MB or GB).
1.1. Output Explanation
The output of df
will typically include the following columns:
- Filesystem: The name of the filesystem.
- Size: Total size of the filesystem.
- Used: Amount of space used.
- Avail: Amount of space available.
- Use%: Percentage of space used.
- Mounted on: Where the filesystem is mounted.
2. Understanding the du Command
The du
command (disk usage) reports the amount of disk space used by files and directories. To check the size of a specific directory:
du -sh /path/to/directory
The -s
option provides a summary, while -h
makes it human-readable.
2.1. Detailed Output
If you want to see sizes for all subdirectories within a directory, run:
du -h /path/to/directory
This will provide a detailed breakdown of disk usage for every subdirectory.
3. Using the Two Commands Together
Combining df
and du
can help you monitor disk usage effectively. For example, use df -h
to check available space and then use du -sh
on directories to ensure you are not running low on space.
4. Checking Disk Usage by File Type
You can also use du
to find out the size of specific file types. For example, to check `.log` files in a directory:
du -ch *.log | grep total
The grep total
displays only the total size of the log files.
5. Conclusion
By mastering the df
and du
commands, you can effectively manage and monitor disk usage on Linux systems. Regularly checking disk usage helps to prevent performance issues and ensures you have sufficient space for applications and files. Continue to explore additional options within these commands to enhance your disk management capabilities!