2

SYSTEM MAINTENANCE

Essential commands and practices to keep your Arch system healthy and running smoothly without breaking things.

ARCH LINUX LAB SERIES

Why Regular Maintenance

Arch Linux follows a rolling release model, receiving constant updates. Unlike Ubuntu or Fedora with scheduled releases, Arch requires regular maintenance to stay clean and performant. A weekly 15-minute routine prevents file accumulation and keeps your system stable.

Clean System

Remove unused packages and cached files

Optimal Performance

Keep disk space free and services running

Prevent Issues

Catch problems before they become critical

Weekly Routine in 9 Steps

  • Check Arch News

    Always visit archlinux.org/news before updating. Some updates require manual intervention. This step can save you hours of troubleshooting.

  • Update System

    # With pacman
    sudo pacman -Syu
    
    # With yay (AUR helper)
    yay -Syu
    Important: Always reboot after kernel updates to use the latest version.
  • Clean Package Cache

    # Keep last 3 versions of each package
    sudo paccache -r
    
    # Remove all versions of uninstalled packages
    sudo paccache -ruk0

    This typically frees between 500 MB to 2 GB of disk space on my system.

  • Remove Orphan Packages

    # List orphan packages
    pacman -Qtdq
    
    # Remove orphan packages
    sudo pacman -Qtdq | sudo pacman -Rns -

    Orphan packages are dependencies no longer needed by any installed package.

  • Manage Configuration Files

    # Find .pacnew and .pacsave files
    sudo find /etc -name "*.pacnew" -o -name "*.pacsave"
    
    # Merge interactively
    sudo DIFFPROG=vimdiff pacdiff
    
    # or with meld (graphical)
    sudo DIFFPROG=meld pacdiff

    When pacman updates a package you've modified, it creates these backup files that need merging.

  • Clean Systemd Journals

    # Check current size
    journalctl --disk-usage
    
    # Keep only last 2 weeks
    sudo journalctl --vacuum-time=2weeks
  • Check Failed Services

    # List failed services
    systemctl --failed
    
    # Investigate specific service
    journalctl -u service-name
  • Clean User Cache

    # Check cache usage
    du -sh ~/.cache/*
    
    # Clean thumbnails
    rm -rf ~/.cache/thumbnails/*
    
    # Clean yay/paru cache
    yay -Sc
  • Check Disk Space

    # Overview
    df -h
    
    # Detailed analysis (install ncdu if needed)
    ncdu /

Automation Script

#!/bin/bash

arch-maintenance.sh

#!/bin/bash

echo "═══════════════════════════════════════════"
echo "  Arch Linux Weekly Maintenance"
echo "═══════════════════════════════════════════"
echo ""

read -p "Have you checked archlinux.org/news? (y/n) " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
    echo "Please check news before continuing."
    exit 1
fi

echo "→ Updating system..."
yay -Syu

echo ""
echo "→ Cleaning package cache..."
sudo paccache -r
sudo paccache -ruk0

echo ""
echo "→ Searching for orphan packages..."
orphans=$(pacman -Qtdq)
if [ -n "$orphans" ]; then
    echo "$orphans"
    read -p "Remove these packages? (y/n) " -n 1 -r
    echo ""
    if [[ $REPLY =~ ^[Yy]$ ]]; then
        sudo pacman -Qtdq | sudo pacman -Rns -
    fi
else
    echo "✓ No orphan packages found"
fi

echo ""
echo "→ Searching for .pacnew/.pacsave files..."
pacnew_files=$(sudo find /etc -name "*.pacnew" -o -name "*.pacsave" 2>/dev/null)
if [ -n "$pacnew_files" ]; then
    echo "$pacnew_files"
    echo "Use 'sudo pacdiff' to merge them"
else
    echo "✓ No configuration files to merge"
fi

echo ""
echo "→ Cleaning systemd journals..."
echo "Current size: $(journalctl --disk-usage | grep -oP '\d+\.\d+[GM]')"
sudo journalctl --vacuum-time=2weeks

echo ""
echo "→ Checking services..."
failed=$(systemctl --failed --no-pager --no-legend)
if [ -n "$failed" ]; then
    echo "⚠ Failed services:"
    echo "$failed"
else
    echo "✓ All services running correctly"
fi

echo ""
echo "→ Disk space:"
df -h / /home | grep -v tmpfs

echo ""
echo "═══════════════════════════════════════════"
echo "  Maintenance Complete"
echo "═══════════════════════════════════════════"
Installation:
# Create the file
nano ~/Scripts/arch-maintenance.sh

# Make executable
chmod +x ~/Scripts/arch-maintenance.sh

# Run it
~/Scripts/arch-maintenance.sh

Monthly Tasks

In addition to weekly maintenance, perform these tasks monthly:

Update Mirrorlist

Use reflector for fastest servers

Firmware Updates

Run fwupdmgr update

Full Backup

Complete system snapshot with Timeshift

Refresh GPG Keys

Keep package signing keys current

Critical Rules

Never Do:
pacman -Sy package Always use -Syu for full updates
Ignore Arch news Some updates require manual intervention
Force conflicting updates Understand conflicts before proceeding
Skip backups Always have bootable USB ready

Quick Reference

# Complete update
sudo pacman -Syu

# System cleanup
sudo paccache -r && sudo paccache -ruk0
sudo pacman -Qtdq | sudo pacman -Rns -
sudo journalctl --vacuum-time=2weeks

# System checks
systemctl --failed
df -h
pacman -Qdt

Conclusion

This 15-minute weekly routine keeps my Arch Linux system stable and performant. Since adopting this discipline, I haven't had any major issues requiring reinstallation.

Arch's advantage is transparency and total control over your system. Regular maintenance investment pays off with long-term stability and performance.