We all mess up in the shell once in a while. Sometimes, while trying to cut corners, we’ll use “>” instead of “>>”, and that will overwrite an important file instead of appending a new line to it.
I was trying to add an unstable keyword to a package in Gentoo, and did just that — I overwrote /etc/portage/package.keywords, and now I can’t for the life of me remember what was in there, apart from WordPress.
Next thing you know, I’m staring at the equery manual page, hoping there’s something akin to “–show-installed-packages-that-are-masked” or “–make-me-less-stupid”, but alas, there’s nothing to be found.
I then notice masked packages that are installed are marked as such in equery list:
[I--] [ ~] dev-util/bzr-0.92-r1 (0)
[I--] [ ~] dev-util/subversion-1.4.5 (0)
[I--] [ ~] net-analyzer/bmon-2.1.0-r3 (0)
[I--] [ ~] net-misc/memcached-1.2.4_rc1 (0)
[I--] [ ~] sys-kernel/xen-sources-2.6.20-r6 (2.6.20-r6)
“It’s a job for grep, sed and awk!” — I shout, brandishing a fist that’s now clenched tightly.
The modem line noise regular expressions that allow you to do this are as follow:
equery --no-pipe list | grep -e '[.~]' | cut -d ']' -f 3 | cut -d ' ' -f 2 | sed -r 's/-[^-]+(-r[[:digit:]])?$//' | uniq
(In case you’re wondering, uniq is in there because slotted packages, such as wordpress, will display multiple times, and we don’t need/want that.)
The output should be as such:
app-portage/eix
dev-perl/Cache-Memcached
dev-php5/pecl-memcache
dev-python/cherrypy
dev-util/bzr
dev-util/subversion
net-analyzer/bmon
net-misc/memcached
sys-kernel/xen-sources
www-apps/wordpress
According to the new nomenclature for package.keywords, you only need to specify the package to use the ~ branch. You should only specify the architecture (~x86, ~ppc, ~amd64) if you want a package for a different architecture. So the output should be suitable for use in /etc/portage/package.keywords.
Hope this helps.

You know, thanks a lot. I just did this exact same thing. Sat there in horror as I realized what had just occured. Thought to myself, “someone, somewhere must have done this before.” And google brought me here. I’m not as versed in equery as I should be, so your post is a real life saver.