Gentoo Wiki


This article is part of the Tips & Tricks series.
Terminals / Shells Network X Window System Portage System Filesystems Kernel Other

When building Xen instances on my work station, I definitely wanted to use quickpkg to make use of what I had on hand -- but I didn't want to make packages of OpenOffice, Mozilla or JDK 1.6! Deft use of equery, egrep, sed and then equery again allows us to filter on many different axes to get rid of a bunch of time-consuming, space-consuming packages.

Code: filtering our packages

##  List installed packages if they are likely to be useful in a Xen
##  instance.

function packages {
  equery --quiet list

##  a helper function, to parse multiline token lists into regex alternations
function tokens_to_alternation {
  echo $1 | sed -r 's/[[:space:]]/|/g'

##  filters out packages in the 'do not want' categories
function category_filter {
    sys-kernel x11- virtual gnome- media-video media-sound net-wireless
  egrep -v "^("`tokens_to_alternation "$do_not_want"`")"

##  eliminate packages with any of the 'do_not_want' tokens in their names
function name_filter {
    mozilla gimp scim uim xvid
    x11 xorg
    opengl mesa glut 
    gtk cairo gnome 
  egrep -v `tokens_to_alternation "$do_not_want"`

##  this is by far the most expensive operation, making multiple calls to
##  equery and writing to a tmp file after every one
function use_flag_filter {
  [ -f $c ] && rm $c
  touch $c

    xorg xv X gnome kde xfs xft glut gtk gtk2 qt qt3 qt4 opengl
  for flag in $do_not_want
    equery --quiet hasuse $flag | sort >> $c
  sort $c | uniq > /tmp/has_gui

  comm -2 -3 - /tmp/has_gui

packages | category_filter | name_filter | use_flag_filter

Retrieved from ""

Last modified: Wed, 26 Dec 2007 15:30:00 +0000 Hits: 2,037