Gentoo one-liners for a rainy day

Published: June 4th, 2025

Updated: July 3rd, 2025

Table of contents

Prerequisites

Install the necessary Portage utilities and GNU Parallel:

emerge -av app-portage/portage-utils app-portage/gentoolkit sys-process/parallel

Finding packages with the most dependencies

Show which packages pull in the greatest number of dependencies:

qlist -CI | sort -u | parallel 'echo $(qdepends -CqqQ {} | wc -l) {}' | sort -n > pkgs_with_most_deps.txt

What each part does:

The output shows dependency count followed by package name, from packages with the least dependencies to greatest.

Finding the largest packages

Find which packages consume the most storage:

qlist -CI | sort -u | parallel qsize -C | awk '{print $NF,$1}' | cut -d ':' -f 1 | sort -h > biggest_pkgs.txt

Breaking this down:

This arranges packages from smallest to largest.

Combining package size and dependency count

Merge dependency and size data in one file for analysis:

join -j 2 -o 1.1,2.1,0 <(sort -k2 pkgs_with_most_deps.txt) <(sort -k2 biggest_pkgs.txt) | sort -n | tr ' ' '\t' > combined.txt

The join command joins lines of two files on a common field:

Print packages without a package.env entry

Print packages not yet customized in /etc/portage/package.env:

comm -13 <(awk 'match($1, /^[a-zA-Z0-9_+-]+\/[a-zA-Z0-9_+-]+$/) {print $1}' /etc/portage/package.env/* | sort -u) <(qlist -CI | sort -u)

This comm usage compares sorted lists:

As above, but only larger packages

Focus on packages large enough to warrant optimization attention:

comm -13 <(awk 'match($1, /^[a-zA-Z0-9_+-]+\/[a-zA-Z0-9_+-]+$/) {print $1}' /etc/portage/package.env/* | sort -u) <(qlist -CI | sort -u) | grep -f - combined.txt | awk 'match($2, /^([0-9]{4}\.[0-9]K)|([0-9]+\.[0-9][MG])$/)' | sort -n

This adds size filtering:

Analyzing upgradeable packages

Find packages not yet customized in /etc/portage/package.env that already need an upgrade:

comm -13 <(awk 'match($1, /^[a-zA-Z0-9_+-]+\/[a-zA-Z0-9_+-]+$/) {print $1}' /etc/portage/package.env/* | sort -u) <(EIX_LIMIT=0 eix -u -# | sort -u)

Multi-column sorting

Use multiple sort keys for different analysis priorities:

sort -k1,1n -k2,2h combined.txt
sort -k2,2h -k1,1n combined.txt

The first command prioritizes dependency count, using size as a tiebreaker. The second makes size the primary criterion. The h and n refer to human-readable and numeric sorting.

Practical applications

These commands identify large packages that can be replaced with lightweight alternatives, which proves useful for several reasons:

I used these commands to guide CFLAGS tweaking to better optimize Gentoo in a Virtual Machine (VM), since VMs have limited resources. I use a setup where video playback doesn’t benefit from hardware acceleration at the time of writing (Qubes OS). I wanted to see if this approach could make a difference.

I think I managed to gain a few Frames Per Second (FPS) from this, but I didn’t benchmark it beyond comparing frame timings in mpv. The gain was relatively minor (<=10fps).

These days I believe strongly in benchmarking and profiling, as they make a real difference. The gains from those techniques typically exceed the gains from CFLAGS tweaking.