Space Checking Methods
Basic Disk Space Checking Commands
1. df Command
The df
command provides a comprehensive overview of disk space usage:
## Display disk space in human-readable format
df -h
graph LR
A[df Command] --> B[Filesystem]
A --> C[Size]
A --> D[Used]
A --> E[Available]
A --> F[Mount Point]
2. du Command
The du
command helps analyze space usage by directories:
## Check directory space usage
du -sh /home/*
## Show top space-consuming directories
du -h /home/* | sort -rh | head -10
Advanced Space Checking Techniques
Disk Partition Space Analysis
Command |
Purpose |
Example Usage |
lsblk |
List block devices |
lsblk -o NAME,SIZE,TYPE,MOUNTPOINT |
fdisk -l |
Detailed partition information |
sudo fdisk -l |
parted -l |
Alternative partition listing |
sudo parted -l |
1. ncdu (NCurses Disk Usage)
Install and use ncdu for interactive disk space analysis:
## Install ncdu
sudo apt install ncdu
## Run ncdu
ncdu /home
- GParted
- Disk Usage Analyzer
Monitoring Disk Space
flowchart TD
A[Disk Space Monitoring] --> B[Regular Checks]
A --> C[Automated Alerts]
A --> D[Preventive Maintenance]
Automated Disk Space Monitoring Script
#!/bin/bash
THRESHOLD=90
CURRENT_USAGE=$(df -h / | awk '/\// {print $(NF-1)}' | sed 's/%//')
if [ $CURRENT_USAGE -gt $THRESHOLD ]; then
echo "Disk space warning: $CURRENT_USAGE% used"
## Send notification or take action
fi
LabEx Tip
LabEx provides interactive Linux environments where you can practice these space checking techniques safely and effectively.
Best Practices
- Regularly check disk space
- Set up monitoring scripts
- Clean unnecessary files
- Use appropriate partitioning strategies