I have Gentoo VM that I use to test different puppet recipes and I frequently need to remove packages to bring it to clean initial state. While I could do this by hand when there are only few packages installed (and remove dependencies with emerge -av --depclean) but there are some recipes involving installation of few dozen of perl modules which I need to clean after testing. I think about packing them into single virtual ebuild but I already have test system dirty with many installed packages and I want to avoid reviewing them one by one. So question is how do I find list of packages installed after some specific date?

2 Answers 2


You can use app-portage/genlop for this.

genlop -l --date some_date

will list all packages merged on or after that date. (You can also specify an end date.)

To get a list of packages suitable for emerge --unmerge, try something like:

genlop -ln --date 2011/10/02 | perl -ne '/>>> (.*)/ and print " =$1";'

Do double-check that list before actually unmerging, removing system packages by accident is not fun.

Another way of getting a list of things merged after a given date is looking at the BUILD_TIME saved in the portage database.

stime=$(date -d "$1" +%s)

for dir in /var/db/pkg/*/* ; do
    if [ -f $dir/BUILD_TIME ] ; then
        if [ $btime -ge $stime ] ; then
            package=$(basename $dir)
            category=$(basename $(dirname $dir))
            echo $category/$package

Call this with a date (i.e. ./script "2001/09/30 21:32") and you'll get a list of packages merged since that date.

Portage doesn't store whether a merge was a new install or an update in its database. You could reconstruct that information from the emerge.log file assuming you have all your system's history there.

A simpler way of handling all this would be to use package sets. Create a set each time you try out a new recipe, and use that to do your cleanups. (Depclean is still necessary.)

# echo dev-perl/IO-AIO > /etc/portage/sets/my_set
# emerge -a @my_set

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild  N     ] dev-perl/IO-AIO-2.33 

Would you like to merge these packages? [Yes/No] y
>>> Recording @my_set in "world" favorites file...

>>> Installing (1 of 1) dev-perl/IO-AIO-2.33
>>> Auto-cleaning packages...

>>> No outdated packages were found on your system.

 * GNU info directory index is up-to-date.
# emerge -a --unmerge @my_set
 * This action can remove important packages! In order to be safer, use
 * `emerge -pv --depclean <atom>` to check for reverse dependencies before
 * removing packages.

>>> These are the packages that would be unmerged:

    selected: 2.33 
   protected: none 
     omitted: none 

All selected packages: dev-perl/IO-AIO-2.33

>>> 'Selected' packages are slated for removal.
>>> 'Protected' and 'omitted' packages will not be removed.

Would you like to unmerge these packages? [Yes/No] 
  • Thanks for suggestion, I've tried it. Unfortunately genlop relies on parsing portage logfiles and doesn't reflect current system state so its output includes already removed packages and some packages are included multiple times as they were installed multiple times and there are also some packages included which happened to be updated at the same time period. So after all I still need to check all packages one by one what I'm trying to avoid.
    – AlexD
    Oct 2, 2011 at 9:26
  • Added more info and a better way to handle your scenario. HTH.
    – Mat
    Oct 2, 2011 at 10:06
  • Thanks, direct access to /var/pkg/db is much better. I've modified your script to use equery depends to skip packages which have anything depended on them so I could get list of packages which is safe to remove without breaking other packages. Sets is interesting feature but it couldn't solve use case when package included in set is also used by some other package which is not included in set, so removing set would break this other package.
    – AlexD
    Oct 7, 2011 at 7:08
  • When unmerging a set, portage does not remove any packages unless they are specifically listed in the set. Generally, packages that would get put into a set are not dependent of other packages in the same set. For instance www-clients/firefox pulls in a bunch of dependencies, but very few packages depend on it. If www-clients/firefox and media-libs/mesa are in the same set, you could just go ahead and remove media-libs/mesa. When you unmerge the set mesa would not get removed. Only when you run emerge --depclean would it get removed and only if no other world or set packages need it.
    – hololeap
    Sep 16, 2014 at 19:55
  • As you continue using Gentoo you will learn when to use the --oneshot flag to avoid putting packages in the "world" set (effectively meaning that they will be removed next time you run emerge --depclean), when to use custom sets, and when to write your own ebuilds for unofficial software (so that you can permanently install any library dependencies without adding them to the "world" set).
    – hololeap
    Sep 16, 2014 at 19:59

This script emerged-after will list all packages emerged after a certain date

etime=`date -d $1 +%s`
eix '-I*' --format '<installedversions:DATESORT>' | cut -f1,3 | cat <(cat -) <(echo $etime) | sort -nr | sed -e/$etime/q | sed -e'/[0-9]*\t*/s///'

You need to have eix installed (if not then emerge eix && eix-update) then call e.g bash emerged-after 31/12/2016

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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