du
Overview
The du
(disk usage) command estimates file space usage. It summarizes disk usage of each file and directory recursively.
Syntax
du [options] [file...]
Common Options
Option | Description |
---|---|
-h |
Human readable sizes |
-s |
Display only total |
-c |
Show grand total |
-a |
Show all files |
-b |
Show size in bytes |
-k |
Show size in kilobytes |
-m |
Show size in megabytes |
--max-depth=N |
Show subdirs only to depth N |
--apparent-size |
Print apparent sizes |
--time |
Show last modification time |
-x |
Stay on one filesystem |
Key Use Cases
- Storage analysis
- Directory size checking
- Disk cleanup
- Space monitoring
- Quota management
Examples with Explanations
Example 1: Directory Summary
du -sh *
Show total size of each item in current directory
Example 2: Depth Limited
du --max-depth=2 /home
Show usage up to 2 levels deep
Example 3: Sort by Size
du -h | sort -hr
Show sorted usage by size
Understanding Output
Format:
Size Path
4.0K ./file1
8.0K ./dir1
12K .
Common Usage Patterns
Find large directories:
du -h --max-depth=1 | sort -hr
Check specific directory:
du -sh /var/log
Show all files:
du -ah
Performance Analysis
- I/O intensive operation
- Directory traversal impact
- Large directory handling
- Memory usage considerations
- Network filesystem impact
Additional Resources
Best Practices
- Use human readable format
- Limit depth for large trees
- Consider filesystem boundaries
- Sort output when needed
- Regular monitoring
Common Issues
- Permission denied errors
- Network latency
- Hard link counting
- Sparse file handling
- Special filesystem types