Overview
du summarizes the amount of disk space used by specified files or directories. It is primarily used to identify files or directories consuming significant disk space or to monitor the disk usage of specific projects.
Key Features
- Calculates disk usage for directories and files
- Outputs in various units (bytes, kilobytes, megabytes, gigabytes)
- Provides total and summary information
- Analyzes usage per subdirectory
Key Options
The main options for the du command control the output format, units, and inclusion/exclusion of items, helping users obtain the desired information.
Output Format and Units
Generated command:
Try combining the commands.
Description:
`du` Executes the command.
Combine the above options to virtually execute commands with AI.
Usage Examples
Learn how to effectively check disk usage through various practical examples of the du command.
Check Total Usage of Current Directory (Human-readable)
du -sh .
Displays the total disk usage of the current directory in a summarized, human-readable format (K, M, G).
Check Usage of Sub-items in a Specific Directory (Gigabytes)
du -g /var/log
Displays the usage of each file and subdirectory within the /var/log directory in gigabytes.
Check Detailed Usage Including All Files
du -ah .
Displays the detailed disk usage of all files and directories in the current directory in a human-readable format.
Check Total Usage of Multiple Directories and Grand Total
du -shc /home/user1 /tmp
Displays the individual usage of /home/user1 and /tmp directories, along with their combined total.
Tips & Precautions
Tips and precautions for using the du command more effectively and avoiding potential issues.
Useful Tips
- You can quickly check the summarized size of each file/directory in the current directory using `du -sh *`.
- Symbolic links by default only calculate the size of the link itself (usually a few bytes). To calculate the size of the target the link points to, use the `-L` option.
- Running `du` on network file systems (NFS) may result in longer execution times due to network latency.
- `du` calculates based on the file system's block size, which may differ from the exact byte count shown by `ls -l`. This is due to the file system's allocation units.