Add the much prettier codegroups to my pacman snippet

This commit is contained in:
Daniel_I_Am 2022-06-15 18:04:15 +02:00
parent 12e6af16c2
commit 1505c5bd1d

View File

@ -8,9 +8,12 @@ draft: false
## Result ## Result
We can find out how many seconds ago the last package was installed or updated using pacman by using the following command: We can find out how many seconds ago the last package was installed or updated using pacman by using the following command:
{{< codegroup >}}
Shell
```sh {data-copy-button=true} ```sh {data-copy-button=true}
echo $(expr $(date +%s) - $(grep -rn -A 1 %INSTALLDATE% /var/lib/pacman/local/*/desc | grep -oP '\d{10,}$' | sort | tail -1)) echo $(expr $(date +%s) - $(grep -rn -A 1 %INSTALLDATE% /var/lib/pacman/local/*/desc | grep -oP '\d{10,}$' | sort | tail -1))
``` ```
{{< /codegroup >}}
--- ---
@ -21,14 +24,19 @@ Pacman stores its local cache on your system at `/var/lib/pacman/local/`. This f
Try reading the files for the kernel for example. We are only interested in the installation date, so let's focus on that field. Try reading the files for the kernel for example. We are only interested in the installation date, so let's focus on that field.
{{< codegroup >}}
Shell
```sh ```sh
$ grep -A 1 '%INSTALLDATE%' /var/lib/pacman/local/linux-5.17.5.arch1-1/desc $ grep -A 1 '%INSTALLDATE%' /var/lib/pacman/local/linux-5.17.5.arch1-1/desc
%INSTALLDATE% %INSTALLDATE%
1651693442 1651693442
``` ```
{{< /codegroup >}}
By running this on all files in the pacman cache directory and then filtering for numbers, you get to see the entire list of dates for every package. By running this on all files in the pacman cache directory and then filtering for numbers, you get to see the entire list of dates for every package.
{{< codegroup >}}
Shell
```sh ```sh
$ grep -A 1 '%INSTALLDATE%' /var/lib/pacman/local/*/desc | grep -oP '\d{10,}$' | head -5 $ grep -A 1 '%INSTALLDATE%' /var/lib/pacman/local/*/desc | grep -oP '\d{10,}$' | head -5
1642498423 1642498423
@ -37,16 +45,23 @@ $ grep -A 1 '%INSTALLDATE%' /var/lib/pacman/local/*/desc | grep -oP '\d{10,}$' |
1640443485 1640443485
1640443485 1640443485
``` ```
{{< /codegroup >}}
Now we just need to sort the entries and pick the highest value. This is the timestamp of our last package installation. Now we just need to sort the entries and pick the highest value. This is the timestamp of our last package installation.
{{< codegroup >}}
Shell
```sh ```sh
$ grep -rn -A 1 %INSTALLDATE% /var/lib/pacman/local/*/desc | grep -oP '\d{10,}$' | sort | tail -1 $ grep -rn -A 1 %INSTALLDATE% /var/lib/pacman/local/*/desc | grep -oP '\d{10,}$' | sort | tail -1
1654790640 1654790640
``` ```
{{< /codegroup >}}
Now we just have to subtract this timestamp from the current date to get the amount of seconds since the last package installation. Now we just have to subtract this timestamp from the current date to get the amount of seconds since the last package installation.
{{< codegroup >}}
Shell
```sh {data-copy-button=true} ```sh {data-copy-button=true}
echo $(expr $(date +%s) - $(grep -rn -A 1 %INSTALLDATE% /var/lib/pacman/local/*/desc | grep -oP '\d{10,}$' | sort | tail -1)) echo $(expr $(date +%s) - $(grep -rn -A 1 %INSTALLDATE% /var/lib/pacman/local/*/desc | grep -oP '\d{10,}$' | sort | tail -1))
``` ```
{{< /codegroup >}}