๐พ Disk Space Management and Cleanup Strategies in AlmaLinux: Simple Guide
Is your AlmaLinux system running out of space? Donโt worry! ๐ Weโll learn how to check disk usage, find whatโs eating up your storage, and clean things up safely. Itโs easier than you think! Letโs make your system breathe again! ๐
๐ค Why is Disk Space Management Important?
Managing disk space keeps your computer happy and healthy! Hereโs why it matters:
- ๐จ Better Performance - More free space means faster system
- ๐ก๏ธ Prevents Crashes - Full disks can cause system failures
- ๐ฆ Install New Software - Need space for updates and programs
- ๐ Smooth Operations - Services need room to work properly
- ๐ Backup Space - Room for important file backups
- ๐ Log Files - System needs space to write logs
๐ฏ What You Need
Before we start cleaning, make sure you have:
- โ AlmaLinux system (any version)
- โ Terminal access
- โ Basic command line knowledge
- โ Admin (sudo) access for some commands
- โ 5-10 minutes to follow along
๐ Step 1: Check Your Disk Space
Letโs see how much space you have left! ๐
Check All Disks
# Show disk usage in human-readable format
df -h
Example output:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 20G 12G 7.0G 64% /
/dev/sda2 100G 45G 50G 48% /home
tmpfs 2.0G 0 2.0G 0% /dev/shm
What this shows: ๐
Size
= Total disk sizeUsed
= Space already usedAvail
= Free space availableUse%
= Percentage used (watch this!)Mounted on
= Where disk is connected
Check Specific Directory
# Check home directory size
du -sh /home
# Check with more detail
du -h /home --max-depth=1
๐ง Step 2: Find Whatโs Using Space
Time to find the space hogs! ๐ท
Find Large Files
# Find files larger than 100MB
find / -type f -size +100M 2>/dev/null
# Find top 10 largest files
find / -type f -exec du -h {} + 2>/dev/null | sort -rh | head -10
Check Directory Sizes
# See sizes of directories in current location
du -h --max-depth=1 | sort -rh
# Check /var directory (common space user)
sudo du -h /var --max-depth=1 | sort -rh
Pro tip: ๐ก The /var
directory often fills up with logs and cache!
๐ Step 3: Clean Package Cache
Package managers save downloaded files. Letโs clean them! ๐งน
Clean DNF Cache
# Check cache size first
sudo du -sh /var/cache/dnf
# Clean all cached packages
sudo dnf clean all
# Remove old packages only
sudo dnf clean packages
Remove Old Kernels
# List installed kernels
rpm -qa kernel
# Keep only 2 newest kernels
sudo dnf remove --oldinstallonly --setopt installonly_limit=2 kernel
What happens: ๐
- Old package files are deleted
- Downloaded metadata is cleared
- Old kernels are removed
- You free up lots of space!
โ Step 4: Clean Log Files
Logs can grow huge! Letโs manage them properly. ๐
Check Log Sizes
# See log directory size
sudo du -sh /var/log
# Find large log files
sudo find /var/log -type f -size +100M
Clean Old Logs
# Clear systemd journal logs older than 7 days
sudo journalctl --vacuum-time=7d
# Or keep only 500MB of logs
sudo journalctl --vacuum-size=500M
# Clear specific log file safely
sudo truncate -s 0 /var/log/messages
Setup Automatic Cleanup
# Configure journal size limit
sudo nano /etc/systemd/journald.conf
# Add these lines:
SystemMaxUse=500M
SystemMaxFileSize=100M
๐ฎ Quick Examples
Example 1: Quick Cleanup Script ๐
#!/bin/bash
# Save as cleanup.sh
echo "๐งน Starting cleanup..."
# Clean package cache
sudo dnf clean all
# Clean journal logs
sudo journalctl --vacuum-time=7d
# Empty trash
rm -rf ~/.local/share/Trash/*
echo "โ
Cleanup complete!"
# Check free space
df -h /
Example 2: Find and Delete Old Files ๐
# Find files not accessed in 30 days
find ~/Downloads -atime +30 -type f
# Delete them (careful!)
find ~/Downloads -atime +30 -type f -delete
# Find and remove .tmp files
find /tmp -name "*.tmp" -mtime +7 -delete
Example 3: Emergency Space Recovery ๐
# When disk is critically full
# 1. Clean package cache immediately
sudo dnf clean all
# 2. Clear all journal logs
sudo journalctl --vacuum-time=1d
# 3. Empty /tmp
sudo rm -rf /tmp/*
# 4. Check space recovered
df -h
๐จ Fix Common Problems
Problem 1: โNo space left on deviceโ โ
Symptoms:
- Canโt save files
- Canโt install updates
- System acting weird
Try this:
# Emergency cleanup
sudo dnf clean all
sudo journalctl --vacuum-time=1d
sudo rm -rf /var/tmp/*
# Find largest files
sudo du -ahx / | sort -rh | head -20
Problem 2: Root partition full โ
Try this:
# Check what's using root space
sudo du -hx --max-depth=1 /
# Common culprits
sudo du -sh /var/log
sudo du -sh /var/cache
sudo du -sh /tmp
Problem 3: Canโt find whatโs using space โ
Check these hidden spots:
# Check for deleted but open files
sudo lsof | grep deleted
# Check docker if installed
docker system prune -a
# Check snap packages
du -sh /var/lib/snapd
๐ Simple Commands Summary
Task | Command |
---|---|
๐ Check disk space | df -h |
๐ Check directory size | du -sh /path |
๐ Find large files | find / -size +100M |
๐งน Clean package cache | sudo dnf clean all |
๐ Clean logs | sudo journalctl --vacuum-time=7d |
๐๏ธ Empty trash | rm -rf ~/.local/share/Trash/* |
๐พ Check top disk users | `du -h / โmax-depth=1 |
๐ก Tips for Success
- Regular Cleaning ๐ - Clean monthly to prevent buildup
- Monitor Usage ๐ - Check disk space weekly
- Set Limits ๐ - Configure log rotation and limits
- Before Deleting โ ๏ธ - Always check what youโre removing
- Keep Backups ๐พ - Save important files before cleanup
๐ What You Learned
Great job! Now you can:
- โ Check disk space usage
- โ Find large files and directories
- โ Clean package cache safely
- โ Manage log files properly
- โ Create cleanup scripts
- โ Recover from full disk situations
๐ฏ Why This Matters
Now your AlmaLinux system:
- ๐ Runs faster with more free space
- ๐ก๏ธ Wonโt crash from full disks
- ๐ฆ Has room for new software
- ๐ Updates smoothly
- ๐ Operates more efficiently
Remember: A clean system is a happy system! Regular maintenance prevents big problems! โญ
Keep your disk clean and your AlmaLinux will thank you! Happy cleaning! ๐งนโจ