From ee9579845e606f28b460233927bea488424cc35f Mon Sep 17 00:00:00 2001 From: Daniel-I-Am Date: Tue, 14 Jun 2022 19:17:58 +0200 Subject: [PATCH] Clean up content --- content/snippets/filler-1.md | 7 --- content/snippets/filler-10.md | 7 --- content/snippets/filler-2.md | 7 --- content/snippets/filler-3.md | 7 --- content/snippets/filler-4.md | 7 --- content/snippets/filler-5.md | 7 --- content/snippets/filler-6.md | 7 --- content/snippets/filler-7.md | 7 --- content/snippets/filler-8.md | 7 --- content/snippets/filler-9.md | 7 --- .../seconds-since-last-pacman-sync.md | 44 ++++++++++++++++++- 11 files changed, 42 insertions(+), 72 deletions(-) delete mode 100644 content/snippets/filler-1.md delete mode 100644 content/snippets/filler-10.md delete mode 100644 content/snippets/filler-2.md delete mode 100644 content/snippets/filler-3.md delete mode 100644 content/snippets/filler-4.md delete mode 100644 content/snippets/filler-5.md delete mode 100644 content/snippets/filler-6.md delete mode 100644 content/snippets/filler-7.md delete mode 100644 content/snippets/filler-8.md delete mode 100644 content/snippets/filler-9.md diff --git a/content/snippets/filler-1.md b/content/snippets/filler-1.md deleted file mode 100644 index 5f2e3e7..0000000 --- a/content/snippets/filler-1.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -title: "Filler 1" -date: 2022-04-16T08:45:13Z -draft: false ---- - -Filler 1 diff --git a/content/snippets/filler-10.md b/content/snippets/filler-10.md deleted file mode 100644 index 2a37c8f..0000000 --- a/content/snippets/filler-10.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -title: "Filler 10" -date: 2022-04-19T08:45:13Z -draft: false ---- - -Filler 10 diff --git a/content/snippets/filler-2.md b/content/snippets/filler-2.md deleted file mode 100644 index fdbcd52..0000000 --- a/content/snippets/filler-2.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -title: "Filler 2" -date: 2022-04-17T08:45:13Z -draft: false ---- - -Filler 2 diff --git a/content/snippets/filler-3.md b/content/snippets/filler-3.md deleted file mode 100644 index d7aae5f..0000000 --- a/content/snippets/filler-3.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -title: "Filler 3" -date: 2022-04-18T08:45:13Z -draft: false ---- - -Filler 3 diff --git a/content/snippets/filler-4.md b/content/snippets/filler-4.md deleted file mode 100644 index 5c4b8d6..0000000 --- a/content/snippets/filler-4.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -title: "Filler 4" -date: 2022-04-19T08:45:13Z -draft: false ---- - -Filler 4 diff --git a/content/snippets/filler-5.md b/content/snippets/filler-5.md deleted file mode 100644 index f21e89d..0000000 --- a/content/snippets/filler-5.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -title: "Filler 5" -date: 2022-04-19T08:45:13Z -draft: false ---- - -Filler 5 diff --git a/content/snippets/filler-6.md b/content/snippets/filler-6.md deleted file mode 100644 index e0e45e2..0000000 --- a/content/snippets/filler-6.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -title: "Filler 6" -date: 2022-04-19T08:45:13Z -draft: false ---- - -Filler 6 diff --git a/content/snippets/filler-7.md b/content/snippets/filler-7.md deleted file mode 100644 index 42f827a..0000000 --- a/content/snippets/filler-7.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -title: "Filler 7" -date: 2022-04-19T08:45:13Z -draft: false ---- - -Filler 7 diff --git a/content/snippets/filler-8.md b/content/snippets/filler-8.md deleted file mode 100644 index 9ca780f..0000000 --- a/content/snippets/filler-8.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -title: "Filler 8" -date: 2022-04-19T08:45:13Z -draft: false ---- - -Filler 8 diff --git a/content/snippets/filler-9.md b/content/snippets/filler-9.md deleted file mode 100644 index d305509..0000000 --- a/content/snippets/filler-9.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -title: "Filler 9" -date: 2022-04-19T08:45:13Z -draft: false ---- - -Filler 9 diff --git a/content/snippets/seconds-since-last-pacman-sync.md b/content/snippets/seconds-since-last-pacman-sync.md index 23a5496..4b3650b 100644 --- a/content/snippets/seconds-since-last-pacman-sync.md +++ b/content/snippets/seconds-since-last-pacman-sync.md @@ -1,11 +1,51 @@ --- title: "Seconds since last pacman sync" -date: 2022-05-19T08:45:13Z +date: 2022-06-11T08:45:13Z tags: ["archlinux", "linux", "pacman"] draft: false --- -We can echo the result of the current timestamp subtracted from the last edit timestamp in `/var/lib/pacman/local/*/desc`. +## Result +We can find out how many seconds ago the last package was installed or updated using pacman by using the following command: + +```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)) +``` + +--- + +## Explanation +Let's dive into the weeds to see how this is built up. + +Pacman stores its local cache on your system at `/var/lib/pacman/local/`. This folder contains a couple files for every package. + +Try reading the files for the kernel for example. We are only interested in the installation date, so let's focus on that field. + +```sh +$ grep -A 1 '%INSTALLDATE%' /var/lib/pacman/local/linux-5.17.5.arch1-1/desc +%INSTALLDATE% +1651693442 +``` + +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. + +```sh +$ grep -A 1 '%INSTALLDATE%' /var/lib/pacman/local/*/desc | grep -oP '\d{10,}$' | head -5 +1642498423 +1644184812 +1640442731 +1640443485 +1640443485 +``` + +Now we just need to sort the entries and pick the highest value. This is the timestamp of our last package installation. + +```sh +$ grep -rn -A 1 %INSTALLDATE% /var/lib/pacman/local/*/desc | grep -oP '\d{10,}$' | sort | tail -1 +1654790640 +``` + +Now we just have to subtract this timestamp from the current date to get the amount of seconds since the last package installation. ```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))