system cleaning

cleaning packages

  1. Check the size of the package cache:
    du -sh /var/cache/pacman/pkg/
  1. Removing packages

    i. Remove uninstalled packages from the cache:

        sudo pacman -Sc
        yay -Sc
    

    ii. Remove all cached packages except for the most recent three versions of each package:

        sudo pacman -S pacman-contrib
    
        sudo paccache -r
    

    iii. Remove all cached packages:

        sudo pacman -Scc
        yay -Scc
    

    iv. Remove orphaned packages (packages that were installed as dependencies but are no longer required by any installed package):

    to list them :

        pacman -Qdt
    

    to remove them:

        sudo pacman -Rns $(pacman -Qtdq)
    

cleaning journal logs

  1. Check the size of journal logs:
    journalctl --disk-usage
  1. Clean journal logs:

    i. Remove journal logs older than a specific time period (e.g., 2 weeks):

        sudo journalctl --vacuum-time=2weeks
    

    ii. Limit the size of journal logs to a specific size (e.g., 500M):

        sudo journalctl --vacuum-size=500M
    

    Note: for more options, you can refer to the man journalctl page and edit /etc/systemd/journald.conf file to set persistent storage and size limits.

clean system temporary files and user cache

  1. Clean system temporary files:
    sudo rm -rf /tmp/*
    sudo rm -rf /var/tmp/*
  1. Clean user cache:
    rm -rf ~/.cache/*
  1. places to look out

    • ~/.config/ – where applications stores their configuration
    • ~/.cache/ – cache of some programs may grow in size
    • ~/.local/share/ – old files may be lying there
    • ~/.streamio-server/ – cache of streamio applications

other useful tools

  • gdu - A disk usage analyzer with a terminal user interface.
  • paccache from pacman-contrib - A utility to manage the package cache of pacman.
  • tmpwatch - A utility to remove files that haven’t been accessed for a specified period of time.
  • bleachbit - A graphical tool to clean unnecessary files and free up disk space.
  • fdupes - A command-line tool to find and remove duplicate files.
  • rmlint - A tool to find and remove duplicate files and other lint on the filesystem.
  • localepurge (AUR) - A tool to remove unnecessary locale files and free up disk space.

automate pacman cleaning

  • Systemd timer create file in /etc/systemd/system/paccache.timer
    [Unit]
    Description=Clean-up old pacman pkg cache

    [Timer]
    OnCalendar=monthly
    Persistent=true

    [Install]
    WantedBy=multi-user.target
  • enable
    sudo systemctl enable paccache.timer
    sudo systemctl start paccache.timer

References