Solved Recently installed packages

Hi!
Maybe anyone knows ho to get list of recently installed packages?
I just want to see packages 'pkg info' sorted by install date.
I learn FreeBSD actively and install many packages. Often on next day I even can't recall name of them...
Ways: history or find executable files sorted by date - can be used but not very comfortable
 
Or make a simple script to get the date of installed packages

Bash:
# Get the package installation date
s="$( pkg query '%t' $package_name )"
# Convert UNIX date to human readable
s="$( date -r $s '+%Y.%m.%d %H:%M:%S' )"
echo "$package_name installed on: $s"

put it in a for loop for each $package_name, sort it, etc, etc
 
$ pkg query %t-%n | sort | awk -F"-" '{ OFS="-"; $1=strftime("%Y-%m-%d %H:%M:%S", $1); print $0 }'

Edit: You can also make this an alias— taking the better -k1n sorting option mentioned below.
sh(1):
alias pkgs='pkg query %t-%n | sort -k1n | awk -F"-" '"'"'{ OFS="-"; $1=strftime("%Y-%m-%d", $1); print $0}'"'"

csh/tcsh(1):
alias pkgs 'pkg query %t-%n | sort -k1n | awk -F"-" '"'"'{ OFS="-"; $1=strftime("%Y-%m-%d", $1); print $0}'"'"

___
P.S. strftime is not documented in FreeBSD's awk(1) manual page; see Thread awk-strftime-undocumented-one-true-awk-awk-1-vs-awk-1.95657
 
Last edited:
Maybe anyone knows ho to get list of recently installed packages?
I just want to see packages 'pkg info' sorted by install date.
Erichans has already provided a one‑liner to list all packages by their installation dates. If you just want a list of recently installed packages, i. e. within a certain time frame:​
Bash:
pkg query -e "%t > $(date -v -14d +%s)" '%n' # -14d means 14 days ago
The -expression evaluates to true if the installation date is greater than the UNIX epoch time %stamp of 14 days ago. NB: 14 days is not necessarily equal to 14 × 24 × 60 × 60 seconds if your location (the selected timezone) observes DST.​
$ pkg query %t-%n | sort | awk -F"-" '{ OFS="-"; $1=strftime("%Y-%m-%d %H:%M:%S", $1); print $0 }'
I find awk(1) always a bit awkward. 🤪 I would have done something like the following. It’s slower since you need to spawn a process (date(1)) and a subshell for every package.​
Bash:
pkg query '%t %n' | sort -k1n | while read ts name ; do printf '%32s  %s\n' "$(date -j -f '%s' $ts)" $name ; done
Note, sort(1) should perform a -numeric sort though as of now this only matters if you have installed packages before the year 2002 or after the year 2285, i. e. when the string lengths of the decimal representation of the installation date varies.​
 
Using the public interface of pkg is definitely the better way to go, but I think there's a SQLite database behind it all, so you can poke that if you don't mind playing with dragons.
Code:
% sqlite3 /var/db/pkg/local.sqlite
sqlite> select datetime(time,'unixepoch', 'localtime'),name from packages order by time desc;
2024-11-08 16:36:45|vim
2024-11-08 16:35:14|py311-tomli
...
I doubt this is recommended, it may not work, it is liable to change etc etc so might be something to have a poke at but please don't rely on it. I just had a quick look at the dates/times in there seem to match the last time I ran upgrades, so it seems it could be a record of what happened. YMMV, caveat emptor, etc.
 
I learn FreeBSD actively and install many packages. Often on next day I even can't recall name of them..
I like to use pkg prime-list because it shows only the packages I manually installed, without the dependencies.
pkg prime-list is an alias for pkg query -e '%a = 0' '%n', this comes from the following file /usr/local/etc/pkg.conf which contains many other alias that you may want to take a look at.
But I prefer this command pkg query -e '%a = 0' '%o' because it shows the full path in the collection tree which can be very useful, sometimes for whatever reason pkg can't find let's say for example git alone but it can find devel/git.

Additionally I use something simalry to what Charlie_ does zgrep -w installed /var/log/message* | less


A pkg history function might be a useful feature. Similar to how yum/dnf history works. It keeps track of when upgrades/installs/removals happen and what they actually did.
Frankly that's one of the few things that surprised me the most when I came to FreeBSD, I didn't say anything because of the Linux rules and since I learned to live with it, but yeah having a /var/log/pkg.log file could be handy.
 
Back
Top