best ways to find and remove unneeded packages/snaps and...

Little Girl littlergirl at gmail.com
Wed Oct 22 15:48:25 UTC 2025


Hey there,

Marco Fioretti wrote:

>I'd like to have ONE script that I can run say every month and:

I'm falling over on that since I'm giving you more than one solution,
but you could probably combine them together.

>1) SAFELY removes from the root partition all the old snaps, logs,
>kernel sources, caches, whatever (did I miss something?)... that is
>not actually needed for the regular working of the system

I believe that Snap cleans up after itself whenever it updates and
the rest of those can be handled by BleachBit, although they can
surely be scripted.

Kernels can be cleaned with this command:

sudo apt autoremove

It removes orphaned packages (that were automatically installed to
satisfy dependencies for some other package(s) and are no longer
needed) from the local repository. It lists the files that would be
removed and lets you choose whether to remove them or not by
requiring a press of a key to proceed from the prompt, with the y or
Enter key removing the files or the n key aborting the process. It
also removes all but three kernels. It does not purge the
configuration files in your user directory for the orphaned packages
it removes. See the bottom of this message for a variant of it that
does remove configuration files.

>2) tells me which packages where installed in the last N days so I
>can quickly figure out which ones where just trial installations I
>could remove because I'm not interested anymore

These two commands will do that and you can change the 30 days I used
for the examples to any number:

grep "Install" /var/log/apt/history.log | awk -v date="$(date
--date='-30 days' +%Y-%m-%d)" '{if ($1 >= date) print}'

grep " install " /var/log/dpkg.log | awk -v date="$(date --date='-30
days' +%Y-%m-%d)" '{if ($1 >= date) print}'

>3) what else should it do? Add your tip

Keep your system up-to-date. Here's my daily command-sequence to
fetch updates and keep my system tidy afterwards:

1. Fetch updates:
	sudo apt update && sudo apt full-upgrade && sudo snap refresh
2. If prompted, reboot and return to step 1.
3. Tidy up:
	sudo apt autoremove --purge && sudo apt clean

Explanation:
* sudo apt update fetches and updates the local list of packages from
  your distribution's software repository and third-party
  repositories 
* sudo apt full-upgrade upgrades all outdated packages that are
  currently installed and uses smart conflict resolution to remove
  currently-installed packages or add new packages, if needed, to
  handle changing dependencies.
* sudo snap refresh updates (refreshes) all Snaps.
* sudo apt autoremove --purge removes orphaned packages (that are no
  longer needed) from the local repository and purges their
  configuration files.
* sudo apt clean removes all packages from the local repository, but
  does not remove the lock file from the
  /var/cache/apt/archives/partial/ directory and from the
  /var/cache/apt/archives/ directory.

-- 
Little Girl

There is no spoon.



More information about the ubuntu-users mailing list