You are not logged in.

#1 2014-10-06 14:46:27

SteveSapolsky
Member
Registered: 2014-08-09
Posts: 16

Sort pacman packages by their installation date

How can I sort packages installed by pacman (pacman -Q) by their installation date?

Offline

#2 2014-10-06 15:00:38

loafer
Member
From: the pub
Registered: 2009-04-14
Posts: 1,772

Re: Sort pacman packages by their installation date


All men have stood for freedom...
For freedom is the man that will turn the world upside down.
Gerrard Winstanley.

Offline

#3 2014-10-06 15:02:32

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,530
Website

Re: Sort pacman packages by their installation date

You can't - at least not via pacman directly.  But the following would mostly work:

 awk '/installed/ {print $5;}' /var/log/pacman.log

This would, however, list every package you've ever installed in date order - it would include removed packages.  But you could elaborate it a bit to filter properly.  In any case, you'd want to draw from the pacman.log.

EDIT: this should do it:

awk '/\[PACMAN\] installed/ {pkgs[$5]=1;} /removed/ {pkgs[$5]=0;} END {for (pkg in pkgs) { if (pkgs[pkg]==1) {print pkg;}}}' /var/log/pacman.log

EDIT: nope, not quite, the associative array mucks up the sorting.  So a slightly more elaborate script would be needed.  But the approach would be similar.

This one requires gawk (which is the default awk in archlinux):

gawk '
BEGIN { n = 0; }
/\[PACMAN\] installed/ {pkgs[n] = $5; n++;}
/removed/ {removed[$5] = 1;}
END { for (i = 1; i <= n; i++) { if (pkgs[i] not in removed) print pkgs[i]; } }
' /var/log/pacman.log

Last edited by Trilby (2014-10-06 15:37:30)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#4 2014-10-06 15:42:00

ml
Member
From: Germany
Registered: 2014-06-21
Posts: 20

Re: Sort pacman packages by their installation date

If you trust the mtime then maybe here is something for you:

long listing
ASC: ls -ltr /var/lib/pacman/local
DESC: ls -lt /var/lib/pacman/local


using find(utils)
ASC: find /var/lib/pacman/local/ -mindepth 1 -maxdepth 1 -type d -printf "%TY-%Tm-%Td %TH:%TM %P\n" | sort
DESC: find /var/lib/pacman/local/ -mindepth 1 -maxdepth 1 -type d -printf "%TY-%Tm-%Td %TH:%TM %P\n" | sort -r

or add -mtime option to display packages older/newer than N days:
older than 30 days: find /var/lib/pacman/local/ -mindepth 1 -maxdepth 1 -type d -printf "%TY-%Tm-%Td %TH:%TM %P\n" -mtime +30 | sort


Output example:

2014-08-28 21:43 cfv-1.18.3-6
2014-08-28 21:43 lsof-4.87-2
2014-08-28 21:46 bzr-2.6.0-1
2014-08-28 21:46 dart-1.6.0-1
2014-08-28 21:46 ecryptfs-utils-104-1
2014-08-28 21:49 libaio-0.3.109-7
2014-08-28 21:50 dosfstools-3.0.26-1
2014-08-28 21:50 grub-1:2.02.beta2-4
2014-08-28 21:50 mtools-4.0.18-2
2014-08-28 22:15 alsa-lib-1.0.28-1

Offline

#5 2014-10-06 15:46:03

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,530
Website

Re: Sort pacman packages by their installation date

That assumes everything installed is still in the cache, and nothing not installed is in the cache.  These are rarely safe assumptions. The pacman.log is a much better source.

EDIT: oops!  sorry, I was completely wrong about that.

Last edited by Trilby (2014-10-06 17:38:19)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#6 2014-10-06 16:48:06

jjacky
Member
Registered: 2011-11-09
Posts: 347
Website

Re: Sort pacman packages by their installation date

It actually uses pacman's local library, not the cache.

Offline

#7 2014-10-06 17:50:44

ml
Member
From: Germany
Registered: 2014-06-21
Posts: 20

Re: Sort pacman packages by their installation date

Trilby wrote:

The pacman.log is a much better source.

It is a "good" source until somebody decides to truncate it wink

Here you go, awk grabbing %NAME% and %INSTALLDATE% from the 'desc' file of each installed local package.

awk '/%NAME%/{getline;PKG=$1} /%INSTALLDATE%/{getline;IDATE=strftime("%Y-%m-%d %H:%M",$1);print IDATE" "PKG}' /var/lib/pacman/local/*/desc|sort

Let me know if there is a better way.

Offline

#8 2014-10-06 17:56:20

HiImTye
Member
From: Halifax, NS, Canada
Registered: 2012-05-09
Posts: 1,072

Re: Sort pacman packages by their installation date

this'll probably do what you want. not the most elegant solution, but should function correctly

awk '/installed/ {print $5" "$1$2;}' /var/log/pacman.log | sort -rut[ -k1,1 | awk '{print $2$3"\t"$1;}'

Offline

#9 2014-10-06 18:19:02

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,530
Website

Re: Sort pacman packages by their installation date

HiImTye, did you try that.  That doesn't work at all here.  An excerpt:

[2013-12-1217:33]	acpi
[2013-12-1216:50]	acl
[2014-04-2916:06]	ack
[2013-12-1217:33]	abs
[2014-06-1715:06]	abiword-3.x-gtk2
[2014-01-3121:47]	aalib
[2014-01-3121:47]	a52dec
[2014-07-2413:15]	The
[2014-02-0511:42]	0ad-data
[2014-02-0511:42]	0ad
[2014-07-1116:51]	/etc/systemd/journald.conf
[2014-09-2714:23]	/etc/sudoers
[2014-06-2316:39]	/etc/shadow
[2014-09-0109:53]	/etc/profile.d/jre.sh
[2014-06-0421:28]	/etc/passwd
[2014-01-0810:54]	/etc/pacman.d/mirrorlist
[2014-05-0907:14]	/etc/makepkg.conf
[2014-02-1010:24]	/etc/locale.gen
[2014-07-1116:51]	/etc/gshadow
[2014-06-0421:28]	/etc/group

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#10 2014-10-06 18:33:29

HiImTye
Member
From: Halifax, NS, Canada
Registered: 2012-05-09
Posts: 1,072

Re: Sort pacman packages by their installation date

yeah, those are hits from output like

[ tye@t: ~ ]$ grep '/etc/clamav/clamd.conf' /var/log/pacman.log
[2014-02-27 17:48] [ALPM] warning: /etc/clamav/clamd.conf installed as /etc/clamav/clamd.conf.pacnew

you could exclude those with something like

grep -v '^/'

after the first awk. I was thinking about this and I don't know if it's the same as a pacman -Qii, because I don't know if it explicitly lists dependencies. it might be better just to filter that output

Offline

#11 2014-10-06 18:48:24

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,530
Website

Re: Sort pacman packages by their installation date

Or just look for "[PACMAN] installed" instead of "installed".


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#12 2014-10-06 18:56:45

HiImTye
Member
From: Halifax, NS, Canada
Registered: 2012-05-09
Posts: 1,072

Re: Sort pacman packages by their installation date

this is the result I came up with on the can *laugh*

pacman -Qii | grep -iE 'name[ ]+:|install date' | sed 's/.*: //' | tac | paste -d " " - -

edit: had to add the string match to the end of 'name' because it caught 'name' in descriptions

Last edited by HiImTye (2014-10-06 18:59:22)

Offline

#13 2014-10-06 18:59:59

ml
Member
From: Germany
Registered: 2014-06-21
Posts: 20

Re: Sort pacman packages by their installation date

Don't use pacman.log
All the information of installed packages can be found in the desc file of each package @ /var/lib/pacman/local


awk example as already mentioned here. Pretty sure this can be shorter but that's like the first thing I wrote using awk.

awk '/%NAME%/{getline;PKG=$1} /%INSTALLDATE%/{getline;IDATE=strftime("%Y-%m-%d %H:%M",$1);print IDATE" "PKG}' /var/lib/pacman/local/*/desc

List of variables you can use:

%NAME%
%VERSION%
%DESC%
%URL%
%ARCH%
%BUILDDATE%
%INSTALLDATE%
%PACKAGER%
%SIZE%
%GROUPS%
%LICENSE%
%VALIDATION%
%REPLACES%
%DEPENDS%
%OPTDEPENDS%
%CONFLICTS%
%PROVIDES%

Offline

#14 2014-10-06 19:02:56

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,530
Website

Re: Sort pacman packages by their installation date

You could use awk instead of grep + sed + ...

Also, that gives the last date it was upgraded instead of the date it was installed.  The local files approaches also has that limitation.  It still seems pacman.log is the best way to go.

Last edited by Trilby (2014-10-06 19:03:43)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#15 2014-10-06 19:04:33

HiImTye
Member
From: Halifax, NS, Canada
Registered: 2012-05-09
Posts: 1,072

Re: Sort pacman packages by their installation date

Trilby wrote:

Also, that gives the last date it was upgraded instead of the date it was installed.

so did my last one, because of the -r option of sort. I assumed that "install date" meant "package install date" not "the first time I installed it"

but yeah, I only know very basic awk usage, hence the other tools

Last edited by HiImTye (2014-10-06 19:06:26)

Offline

#16 2014-10-06 19:06:30

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,530
Website

Re: Sort pacman packages by their installation date

The date a package was installed would be when you installed the package.  But pacman -Qi (and the /local/ files) only tells you when you installed the current version, not when you installed the package itself.  The pacman.log does differentiate between when they were installed and upgraded.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#17 2014-10-06 19:48:59

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: Sort pacman packages by their installation date

SteveSapolsky wrote:

How can I sort packages installed by pacman (pacman -Q) by their installation date?

expac --timefmt=%s '%b\t%n' | sort -n

Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#18 2014-10-06 19:52:30

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,530
Website

Re: Sort pacman packages by their installation date

expac also seems to get the date of the last upgrade rather than the install.

EDIT: scratch that - I'm not sure what that does.  I had to install expac to test out that command, yet expac is listed in the middle of it's own output.  It was the very last package I've installed, and the last current version to be installed, yet it is right in the middle of the resulting list (edit: ah, that's the build date, not install date, but also the install date does give the last version upgrade, not the original install).

Last edited by Trilby (2014-10-06 19:54:17)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#19 2014-10-06 22:54:50

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: Sort pacman packages by their installation date

Trilby wrote:

expac also seems to get the date of the last upgrade rather than the install.

EDIT: scratch that - I'm not sure what that does.  I had to install expac to test out that command, yet expac is listed in the middle of it's own output.  It was the very last package I've installed, and the last current version to be installed, yet it is right in the middle of the resulting list (edit: ah, that's the build date, not install date, but also the install date does give the last version upgrade, not the original install).

The manpage takes the guess work out of this. %b is the build date of the package. %l is the date that the package was installed (that specific package, not necessarily the first time it appeared on your system).

Offline

Board footer

Powered by FluxBB