Skip to content

A convenient way to "purge" useless packages?

As many of you I guess, after a long time without reinstalling we have thousands of packages Installed, few days ago I ran out of storage in my root partition and needed to expand it. Is there a way to purge this thing ? I could think something like a list of packages which are not dependencies and haven't been used for a long time, is there a way to get such a list ? Thanks in advance

128 points32 comments
Open on Reddit
About this post
Posted
Archived
Score
128 · 96% up
Kind
Text
ID
ig8ism

Author

21
posts
307
comments
3
media
View profile

33 comments

Are you deleting the older packages from the pacman cache?
If you don't delete them it just keeps using space with the new versions, you can install pacman-contrib for the paccache script for a quick way to delete them.

As to packages that are no longer used you can check for orphans with this:

To list all packages no longer required as dependencies (orphans):
$ pacman -Qdt  

https://wiki.archlinux.org/index.php/Pacman#Querying_package_databases

63 points

Thanks, no I wasn't doing anything like that, bit what I meant by none used packages was packages that aren't needed by any other and haven't been launched in a while, like maybe I have 5 or 6 terminals in my system, tested them all and then only run termite last 3 months but forgot to delete them and want them to be listed

9 points

There's no way to list packages that you haven't launched, no.

You can use pacman -Qe to list all explicitly installed packages though, and just go through the list removing anything you don't use anymore.

You might want to check your package cache size too and clear out old packages. You can use pacman -Sc or you can check out paccache from pacman-contrib.

30 points

This.

Once I got my root partition full. Whith du I found out the cache was using several GB.

3 points

My favorite command is du -hxd2 --time / | sort -rh | head.

5 points
unknown author3 hidden

does this distinguish packages I installed myself vs. packages pulled as dependency?

can I list all packages installed myself and perhaps unmark them somehow, so they'll seen as orphans?

2 points

take a look at man pacman if you haven't (search for keywords with / and nN). For instance under -Q for all the flags available for the query operation, which can be combined for a variety of use cases.

7 points

Packages you installed (explicitly installed) will not show up under pacman -Qdt You can list all explicitly installed packages with pacman -Qe To mark explicitly installed packages as dependencies (i.e unmark them): pacman -D --asdeps *package_name* (as sudo or root) *Edit: Markdown syntax

2 points

pacman -Rns $(pacman -Qtdq)

37 points

Let me see if I understand this.

-Q queries the package database

-t prints packages neither required nor optionally required by any installed packages.

-d lists packages that are installed as dependencies, and combined with -t lists orphans.

-q is just to print less info.

So pacman -Qtdq lists packages that were installed as dependencies but are no longer.

Wrapping it with -Rns will remove packages that are found in the sync database (-n) and all their dependencies (-s), using the output of -Qtdq as the package list.

Thanks.

39 points

The -q is needed to only print the names, otherwise the versions would be printed as well and pacman -Rns wouldn't work.

It should be noted though, that yay has a wrapper for this. Just do yay -c. If you're using a different helper (or none at all) just alias it

14 points

BACKUP your system before do any of this.

list orphans (dependencies not required by any other packages, including the packages that installed during building the package from aur, set them to explicitly installed if you want to exclude them from orphans): pacman -Qdt

remove orphans ('q' mean show less info i.e name of package only): pacman -Rns $(pacman -Qdtq)

list of explicitly installed packages (remove 'q' to see more info of package i.e version/build). select and remove undesired packages (search on the internet to see if the selected packages is required by the system, if not, remove them at you own risk): pacman -Qenq

to remove package: pacman -Rns <package_name>

clear cache: pacman -Scc

see arch wiki for more.

9 points

Just yesterday I got back 5Gb from clearing the cache.

pacman -Scc

It’s worth removing dependencies (d) that aren’t needed anymore (t):

# See the list
pacman -Qdt
# Get ‘em outta here!
pacman -Rns $(pacman -Qdtq)

Take a look at the packages you installed (not dependencies) - unfortunately, I don’t know how to sort by date.

pacman -Qet

Most importantly, look around the file system. Spotify will build a multi-gig cache pretty quickly, for example. This is my favorite command:

# Human-readable
du -hd 1 | tee disk_usage.txt
# Alternatively, for sorting
du -d 1 | sort -n | tee disk_usage.txt
7 points

Also try ncdu. It's interactive.

6 points

This....won't tell you about dangling packages but if you have anything else taking up space (VMs, cache, config, etc) this will find it.

2 points

As others have said, pacman cache is worth clearing out.

Also, depending on what you use your system for, some digging around with du might be worthwhile. Maybe it's not installed software filling your disk but something else.

5 points
unknown author4 hidden

Clearing the cache will give you more room.

Try this:

  1. mkdir /etc/pacman.d/hooks/clean_package_cache.hook
  2. cd /etc/pacman.d/hooks
  3. Your favorite editor clean_package_cache.hook
  4. Add

[Trigger]

Operation = Upgrade

Operation = Install

Operation = Remove

Type = Package

Target = *

Description - Cleaning pacman cache...

When = PostTransation

Exec = /usr/bin/paccache -rk2

3 points

You need to fix step one. You don't want to create a directory called clean_package_cache.hook

2 points

I thought it would be interesting to check the file in each package which was most recently accessed to see if there were any packages that I haven't used in a while. I'm learning python so I wrote this. Feel free to try it. For each package, it finds the most recently accessed file and prints the days since it was last accessed, the package, and the file name.

run it with python. No arguments will check all installed packages. Or you can give it some package names. Pipe it to sort -n to organize the results.

import os
import subprocess

import sys
if len(sys.argv) > 1:
    package_list = sys.argv[1:]
else:
    result = subprocess.run(['pacman', '-Qq'], stdout=subprocess.PIPE)
    package_list =  result.stdout.decode().splitlines()

import datetime
now = datetime.datetime.now()

class Package:
    def __init__(self, name=None):
        self.name = name
        self.files = []
        self.most_recently_accessed_file = None

class File:
    def __init__(self, path=None, atime=None):
        self.path = path
        self.atime = atime
        self.atime_diff = now - atime

packages = []

for package in package_list:
    p = Package(package)
    result = subprocess.run(['pacman', '-Qlq', package], stdout=subprocess.PIPE)

    for filename in result.stdout.decode().splitlines():
        #if os.path.isfile(filename) and os.access(filename, os.X_OK):
        if os.path.isfile(filename):
            p.files.append(File(filename, datetime.datetime.fromtimestamp(os.path.getatime(filename))))
    packages.append(p)

for p in packages:
    for f in p.files:
        if p.most_recently_accessed_file is None or f.atime_diff < p.most_recently_accessed_file.atime_diff:
            p.most_recently_accessed_file = f
    if p.most_recently_accessed_file is not None:
        print("{}\t{}\t{}".format(p.most_recently_accessed_file.atime_diff.days, p.name, p.most_recently_accessed_file.path))
3 points

I don't think there's an easy way to find useless packages in the way you mean it because nothing is explicitly keeping track of when you're using the contents of a package. The other answers have already noted some ways in which you can get rid of useless packages, but here's another tip:

Sort the packages by size and consider whether you actually need the largest ones. Most are pretty small so this shouldn't take long. See here on how to do it.

1 points

Checking the atime of each file of each package would do this, right?

2 points

There's a pacman hook that will also delete old cached packages save the most recent 1-2, can help you automatically keep space free. See this thread

1 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.