October 12, 2020

OpenBSD: Size of installed packages

Sometimes you may need to remove packages to make some place in your hard drive. The first thing you could try is to

# pkg_delete -ac

That should remove unused dependencies and extra configuration files, so that you will win some space.

If this is not enough, then run the following to have a look at what packages are the biggest in your installation

$ pkg_info -as | sed ':a;N;/\nInformation/!s/\n/ /;ta;P;D' | sort -k 5 > InstalledPackSize.txt

What sed is doing here is the following:

:a                         # Label to jump to
N                          # Append next line to pattern space
/\nInformation/!s/\n/ /    # If the newline is NOT followed by "Information", 
                           # append the line by replacing the newline with a space
ta                         # If we changed something, jump to label
P                          # Print part until newline
D                          # Delete part until newline

and then decide what you want to remove.