Wednesday, February 10, 2010

List installed packages sorted by date/size in FreeBSD

For tcsh:

alias pkg.size 'pkg_info | awk '\''{print $1}'\'' | xargs pkg_info -sQ | sort -n -t: -k2 -r | awk -F: '\''{printf("%12s\t%s\n", $2, $1)}'\'' '
alias pkg.date 'ls -ltT /var/db/pkg/*/+CONTENTS | sed -E "s/.*(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)(.+)\/var\/db\/pkg\/(.+)\/\+CONTENTS/\1\2\3/"'

Resize your browser window if you can't see the end of the lines. Pay attention to all quotes in 2 lines above, otherwise aliases may not work.

Then, for example, you can print package list sorted by size:

% pkg.size
   277980976    jdk-doc-1.6.0.10
   158015255    diablo-jdk-1.6.0.07.02
         ...
        2226    bigreqsproto-1.0.2
        1815    font-micro-misc-1.0.0

Or print package list sorted by installed date:

% pkg.date
Feb  9 10:46:06 2010 firefox-3.6,1
Feb  9 08:35:54 2010 inn-2.4.6_1
...
Jan  8 04:48:58 2009 pkg-config-0.23_1
Jan  8 04:48:57 2009 kbproto-1.0.3

Not a big deal but still useful.

2 comments:

  1. freebsd10 adjustment. I only did size. gl.
    alias pkg.size 'pkg info | awk '\''{print $1}'\'' | xargs pkg info -s | sort -n -t: -k2 -r | awk -F: '\''{printf("%12s\t%s\n", $2, $1)}'\'' '

    ReplyDelete
  2. Hi, this is a variant to list date,name,version of installed ports with "pkg info"
    pkg info -a -f | grep -A 2 Name | awk -F "--" '/Name :/{split($1,name,":"); getline; split($1,version,":") ; getline; split($1,date," "); print date[8] " " date[5] " " date[6] "\t" name[2] version[2]}'

    ReplyDelete