Advanced Usage Scenarios
Complex Disk Usage Analysis
Advanced du
command techniques enable sophisticated disk space management and system optimization strategies.
Filtering and Exclusion Techniques
Excluding Specific File Types
## Exclude .log files from disk usage calculation
du -h --exclude="*.log" /var/log
Handling Large Directories
## Find top 10 largest directories
du -h --max-depth=1 | sort -rh | head -n 10
Scripting and Automation
Disk Space Monitoring Script
#!/bin/bash
## Automated disk space monitoring
THRESHOLD=80
CURRENT_USAGE=$(df -h / | awk '/\// {print $(NF-1)}' | sed 's/%//')
if [ $CURRENT_USAGE -gt $THRESHOLD ]; then
du -h --max-depth=2 / > disk_usage_report.txt
fi
Comparative Analysis Strategies
Scenario |
Command |
Purpose |
System-wide Analysis |
du -hx / |
Comprehensive disk usage |
User-specific Check |
du -sh ~/ |
Personal directory size |
Specific Filesystem |
du -h --max-depth=1 /home |
Targeted exploration |
Workflow Visualization
graph TD
A[Disk Usage Analysis] --> B{Select Strategy}
B --> |Filtering| C[Exclude Specific Files]
B --> |Monitoring| D[Automated Reporting]
B --> |Performance| E[Optimize Depth]
E --> F[Generate Insights]
- Use
--max-depth
to limit recursive scanning
- Combine with
find
for precise file selection
- Leverage pipe (
|
) for advanced filtering
Real-world Application Example
## Find directories consuming more than 1GB
du -h | awk '$1 ~ /^[0-9.]+G/ {print $0}'
LabEx Practical Recommendation
Explore advanced du
techniques in LabEx's controlled Linux environments to develop robust system administration skills.