pkg query timestamp format

J.B. non.euc.geo.1854 at
Sat Aug 17 19:38:07 UTC 2019

On 7/13/19 5:00 AM, freebsd-questions-request at wrote:
>> When I use the following command, I get packages with timestamp
>> installed in epoch Unix time. Is there any way to format that date into
>> month, day and year?
>> pkg query %n-%t
> Judging from "man pkg-query", the %t information (timestamp
> of installation) cannot be changed into a different format.
> But according to "man date" and "man strftime", there is a
> solution, which is only_half_  a solution because my script
> foo fails to provide a way to keep the package name, but hey,
> the dates_can_  be converted.
> 	pkg query %n/%t | cut -d '/' -f 2 | xargs -n 1 -J @ date -j -f "%s" @ "+%Y-%m-%d_%H:%M:%S"
> I didn't find a way to feed one information of the $n/%t
> pair unaltered and uninterpreted (!) into date, but the
> conversion of the date Epoch -> YYYY-MM-DD_HH:MM:SS works.
> With an enclosing script it would probably be much easier,
> but at the moment, I can only provide this one-liner as an
> inspiration for further coding...:-)

Here's a modified version of your solution in awk:

    # pkg query %n/%t | awk '{ print $1 } { system("date -j -f \"%s\" "
    $NF " \"+%Y-%m-%d_%H:%M:%S\"") }' FS=\/ ORS=\\t
    xterm   2019-08-16_10:32:13
    xvid    2018-12-25_00:19:03
    xvinfo  2019-04-20_12:29:07

More information about the freebsd-questions mailing list