In this article, we're going to learn how to

  • Clean package cache

  • Remove unused packages (orphans)

  • Clean the cache in our /home directory

  • Remove old config files

  • Remove duplicates, empty files, empty directories and broken symlinks

  • Find the largest files and directories

  • Clean Systemd journal

NOTE that we may need to backup our linux system before the cleaning work.

Clean package cache

Pacman stores all the downloaded packages in /var/cache/pacman/pkg/ and it does not remove the old or uninstalled versions automatically.

We can use du to check the size of the package cache before removing

1
2
❯ du -sh /var/cache/pacman/pkg
23G     /var/cache/pacman/pkg

Remove cached packages that are not currently installed

1
sudo pacman -Sc

Remove all the packages from the cache, including the installed ones

1
sudo pacman -Scc

Remove unused packages (orphans)

Find the unused packages (orphans)

1
2
❯ sudo pacman -Qtdq
js78

Remove them

1
2
3
4
5
6
7
8
❯ sudo pacman -Rns $(pacman -Qtdq)
checking dependencies...

Packages (1) js78-78.15.0-4

Total Removed Size:  62.31 MiB

:: Do you want to remove these packages? [Y/n]

Clean the cache in /home directory

First we can check the size of the cache within /home directory

1
2
❯ du -sh ~/.cache
1.2G    /home/zjh/.cache

Then remove all the cache files

1
rm -rf ~/.cache/*

Remove old config files

Arch Linux stores the configuration files in ~/.config/, sometimes, may also put some old files in ~/.local/share/.

We can check the folders in there and remove the ones we don't need.

Remove duplicates, empty files, empty directories and broken symlinks

We can use rmlint to remove duplicates, empty files, empty directories and broken symlinks

1
sudo pacman -S rmlint

Execute rmlint with specifying the directory we want to check

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
❯ rmlint ~
...
==> Note: Please use the saved script below for removal, not the above output.
==> In total 30320 files, whereof 4185 are duplicates in 2629 groups.
==> This equals 0.63 GB of duplicates which could be removed.
==> 519 other suspicious item(s) found, which may vary in size.
==> Scanning took in total 3.391s.


Wrote a sh file to: /home/xxx/rmlint.sh
Wrote a json file to: /home/xxx/rmlint.json

After executing the command above, rmlint will generate rmlint.sh and rmlint.json. We can open the files to check which files, directories or broken symlinks will be removed.

And then execute rmlint.sh to perform deletion.

1
sh -c rmlint.sh

Find the largest files and directories

We can use ncdu to find the largest files and directories

1
sudo pacman -S ncdu

Clean Systemd journal

Systemd storers logs in /var/log/journal/.

We can keep the latest logs by limiting the size

1
sudo journalctl --vacuum-size=500M # only keep 500mb of the latest logs

or by limiting the time

1
sudo journalctl --vacuum-time=4weeks

We can also let the system to automatically clean the logs by setting SystemMaxUse in /etc/systemd/journald.conf

1
SystemMaxUse=500M

Ref