How to free up disk space in Arch Linux

October 18, 2022-3 min read

In this post you'll learn how to clean your Arch Linux system and reclaim valuable disk space.

Remove unused packages

Many packages in your system are installed as dependencies of other packages. If you remove such a package, its dependencies will not be removed automatically. To check for such unused dependencies run:

sudo pacman -Qtdq

The -Q option will query the packages database for unused packages (-t) that were installed as dependencies (-d). The -q option will display just the packages names, which is useful for running this command as a script like below.

To remove the above packages run:

sudo pacman -Rs $(pacman -Qtdq)

The -s option will remove packages recursively, meaning that it will also remove the dependencies of the unused packages as long as they are not needed by another package and they are not installed explicitly by the user.

Clean the package cache

Pacman stores its downloaded packages in /var/cache/pacman/pkg/ and does not remove old or uninstalled versions automatically. You can either remove old packages manually or use a script.

The manual way

Check the packages that exist in the pacman cache:

ls /var/cache/pacman/pkg/

To remove all cached packages except from those that are installed

sudo pacman -Sc

If you want to remove all cached packages

sudo pacman -Scc

Using paccache

An alternative to the manual removal of packages is paccache; a script that deletes all cached versions of installed and uninstalled packages, except for the most recent three, by default. First install paccache

sudo pacman -S pacman-contrib

Check which packages can be removed

paccache -d

Delete the packages

paccache -r

Run paccache automatically

You can also enable and start the paccache.timer service to automatically remove unused packages weekly:

sudo systemctl enable paccache.timer
sudo systemctl start paccache.timer

Clean home directory cache

Your applications will use the .cache directory in your home directory to store cached data. Usually it's safe to remove files from here as applications will recreate any needed data. Proceed with caution though.

You can use the following command to check which directories are taking up most of the space

du --max-depth=1 ~/.cache | sort -hr

Alternatively you can use the ndcu tool, a disk analyzer with an ncurses interface.

Find and remove duplicate files

rmlint is a handy tool that scans your filesystem to find duplicate files and directories.

rmlint will also detect empty directories and broken symbolic links. While they don't take any meaningful disk space, they still clutter your system.

Install rmlint using:

sudo pacman -S rmlint

and run it:

rmlint -g [directory]

After it completes, rmlint will create a rmlint.sh script in the directory where it was executed. You can inspect the script to check what is going to be deleted, manually remove any files you want to keep, and finally execute the script.

Clean Systemd journal

Systemd logs are stored in the /var/log/journal directory. By default, systemd will retain logs up to 10% of the size of the filesystem, capped to 4G.

Keep the most recent 100M of logs

sudo journalctl --vacuum-size=100M

Delete all logs older than one week

sudo journalctl --vacuum-time=1week