You are not logged in.

#1 2011-03-27 10:44:04

Dganic
Member
Registered: 2011-01-04
Posts: 14

Removing unused packages

By a youth / stupidity ponastavil any different software packages which are now not using, as if to find all unused packages and carry them?
Maybe there is some special tool or means pacman can do that?
Thanks in advance

Offline

#2 2011-03-27 11:02:50

bohoomil
Banned
Registered: 2010-09-04
Posts: 2,377
Website

Re: Removing unused packages

If the packages were explicitly installed, then the only way is to explicitly remove them. You may want to list your packages by their install date (the method was described here: https://bbs.archlinux.org/viewtopic.php?id=86110), or inspect you pacman.log to remove the desired/most recent items, but more "educational" is a study of /var/lib/pacman/local, which prevents from future extensive installing. ; )

If you want to remove obsolete dependencies, then

pacman -Qdt

works fine.

Last edited by bohoomil (2011-03-27 11:08:32)


:: Registered Linux User No. 223384

:: github
:: infinality-bundle+fonts: good looking fonts made easy

Offline

#3 2011-03-27 11:23:43

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,731
Website

Re: Removing unused packages

Get pacgraph from the AUR and you can see packages roughly by size via the -c switch.

Offline

#4 2011-03-27 14:24:45

Dganic
Member
Registered: 2011-01-04
Posts: 14

Re: Removing unused packages

It's a bit of everything is not something I would like to know what packages I did not address such a month and then remove them

Offline

#5 2011-03-27 14:33:56

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,731
Website

Re: Removing unused packages

Dganic wrote:

It's a bit of everything is not something I would like to know what packages I did not address such a month and then remove them

I don't believe there is such an app.

Offline

#6 2011-03-27 19:10:24

vae77
Member
Registered: 2010-07-02
Posts: 75
Website

Re: Removing unused packages

But  that would be cool for analysis. Find with atime parameter could be used for..

Offline

#7 2011-03-27 21:05:52

thisoldman
Member
From: Pittsburgh
Registered: 2009-04-25
Posts: 1,172

Re: Removing unused packages

How about 'ls -ltu'?

I can't test this, because I've disabled atime in fstab.

Last edited by thisoldman (2011-03-27 21:09:16)

Offline

#8 2011-03-27 21:16:34

vae77
Member
Registered: 2010-07-02
Posts: 75
Website

Re: Removing unused packages

I've write a not efficient python script for this. It seems to work smile

#!/usr/bin/python

import os
import time
import re
import sys
from datetime import datetime, timedelta

def list_unused_packages(days):
    '''
    list packages not acessed in arch for n days
    it checks if any of files in package were acessed before n days,
    if not add it to list of unused_packages.
    '''
    lt_time = datetime.now() - timedelta(days=days)
    epoch_lt_time = time.mktime(lt_time.timetuple())

    # get list of installed packages
    installed_packages = os.popen('pacman -Q').read().split('\n')[:-1]


    unused_packages = []
    for package in installed_packages:
        # get files of package
        files = os.popen('pacman -Ql ' + re.match('^.* ', package).group())
        files = files.read().split('\n')[:-1]
        acessed = False
        for path in files:
            valid_file = re.search(' (.*\w)$', path) # exclude directories
            if valid_file:
                try:
                    atime = os.path.getatime(valid_file.group(1))
                    if atime > epoch_lt_time:
                        acessed = True
                        break
                except OSError:
                    # broken symlink?
                    pass
        if not acessed:
            unused_packages.append(package)

    return unused_packages


if __name__ == '__main__':
    try:
        unused_packages = list_unused_packages(int(sys.argv[1]))
        print ('\n'.join(unused_packages))
        if unused_packages:
            print ('packages not used for at least {0} days'.format(sys.argv[1]))
        else:
            print ('all packages were acessed.')
    except IndexError:
        print ('usage: unused_packages days')

Last edited by vae77 (2011-03-27 21:32:28)

Offline

#9 2011-03-27 21:40:47

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: Removing unused packages

Make the code quick and dirty, not the execution! Though, on my SSD, this is actually pretty quick (less than 3s).

#!/bin/bash

declare -A usage

exec 0< <(pacman -Ql | grep bin)

while read pkg binary; do
  lastused=$(stat -c '%X' "$binary")
  if [[ -z ${usage[$pkg]} ]] || (( lastused > ${usage[$pkg]} )); then
    usage[$pkg]=$lastused
  fi
done

for key in "${!usage[@]}"; do
  printf '%s\t%s\n' "${usage[$key]}" "$key"
done | sort -rn | while read time pkg; do
  printf '%(%c)T\t%s\n' "$time" "$pkg"
done

This doesn't actually work for folks who set noatime on their drive though, e.g.:

Mon 17 Jan 2011 01:48:41 PM EST    less

I have a funny feeling I've used less since January.

Offline

#10 2011-12-11 13:43:29

huvber
Member
Registered: 2011-04-12
Posts: 42

Re: Removing unused packages

your code have an error

Offline

#11 2011-12-11 14:04:37

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Removing unused packages

huvber wrote:

your code have an error

More info would be welcome.

Offline

Board footer

Powered by FluxBB