For some reason I have installed a lot of packages on my Linux distros (Fedora/CentOS/Debian/Ubuntu/Arch/...). Some of them are only for one-time use. But they will be included for upgrade whenever I run a full system upgrade with the package manager. In this case, those one-time packages simply waste time and bandwidth because they are actually not needed any more. Therefore I want to figure out what they are exactly and remove them.

I know some package managers allow you to install packages as dependencies so that they can be automatically removed when their downstream packages are removed. But sometimes I forget to add this option when installing packages, and some of those packages are installed by scripts which didn't use the as-dependency option. So the current situation is, I don't know which packages are no longer in use.

I think one way to identify these packages is to track the last access time of package files. But I'm not aware of a method to do so using any of the popular package managers (dnf/yum/apt/pacman/...). Does any of them have such a functionality or similar functionality which allows me to identify and remove those one-time packages? A cumbersome way of doing so is to get a full list of files for all packages and sort by their access time. But before I do this I'd like to make sure I'm not reinventing the wheels (i.e. making something a package manager already has).

closed as too broad by jasonwryan, Jeff Schaller, Thomas Dickey, A.B, Thomas Sep 1 '18 at 6:27

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    What is your distribution? – Ravexina Aug 31 '18 at 21:55
  • @Ravexina Any of Fedora/CentOS/Debian/Ubuntu/Arch or whatever distro you know of. If one package manager works then maybe there are ways to get things done with other package managers. – Cyker Aug 31 '18 at 21:58
  • Are you looking for manually installed packages that no other package is depend on? am I getting this right? – Ravexina Aug 31 '18 at 22:24
  • @Ravexina Nope, it's about finding packages that have been installed but used very rarely. If these packages are installed as dependency then it's trivial to remove them. So the real problem is when they are (incorrectly) installed as explicitly required. – Cyker Sep 1 '18 at 1:58

On Debian/Ubuntu, this gives you the most recent access time of any file in a given package:

function package_access { dpkg-query -L $1 | xargs stat -c '%F %n' | grep '^regular file ' | sed 's/^regular file //' | xargs stat -c '%x' | sort -r | head -1 ; }

(if there are no spaces/parentheses in the names).

So you can list your packages with their latest access times with:

( for p in $(dpkg-query -f '${Package}\n' --show); do echo "$(package_access "$p") $p" ; done ) | sort -r

(which will run for some time and also output a lot of crap, see caveat above)

Curiously, on my Ubuntu 16.04 installed in May 2017, it finds packages with access times going as far back as 2007 (tk, due to it's only real file /usr/share/doc/tk/copyright). But accessing one file in such package brings back the package_access output to the present.

  • Thank you for the idea. I think it probably works. But the output formats of those package managers need some tweaking. – Cyker Sep 1 '18 at 2:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.