Pacman clean unused packages

Package managers can detect which packages were manually installed (at user or script explicit request) and which were implicitly installed as a prerequisite. When uninstalling the manually installed package, the prerequisite packages are often not auto-uninstalled. To recover a significant amount of disk space (gigabytes perhaps) from unused packages, an autoremove command is useful.

Pacman is used in numerous Linux distros and in MSYS2. Show the auto-installed prerequisites:

pacman -Qdtq

This can be piped into the Pacman remove command upon verifying the packages above are indeed OK to remove:

pacman -Qdtq | pacman -Rs -

The package cache can contain gigabytes no longer needed. The pacman cache is cleared by:

pacman -Sc

Related: Clean APT and DNF cache