Updating, Listing and Who Owns a File

Keeping the system up to date

Two steps, on every package manager. First refresh the catalogue, then upgrade. On Ubuntu it's apt update then apt upgrade; here:

sudo apk update
apk list -u

In the terminal (-u: the installed packages that have a newer version)

student@vulntech:~$ sudo apk update
[sudo] password for student:
vulntech local packages [/srv/packages/main]
OK: 151 distinct packages available
student@vulntech:~$ apk list -u
libcrypto3-3.3.7-r2 x86 {openssl} (Apache-2.0) [upgradable from: libcrypto3-3.3.2-r4]
libssl3-3.3.7-r2 x86 {openssl} (Apache-2.0) [upgradable from: libssl3-3.3.2-r4]
musl-1.2.5-r11 x86 {musl} (MIT) [upgradable from: musl-1.2.5-r8]

apk list -u shows what could be upgraded without touching anything. To preview the upgrade itself, add -s (simulate): it prints exactly what would change and makes no changes:

sudo apk upgrade -s

In the terminal

student@vulntech:~$ sudo apk upgrade -s
[sudo] password for student:
(1/3) Upgrading musl (1.2.5-r8 -> 1.2.5-r11)
  0%                                                                           (2/3) Upgrading libcrypto3 (3.3.2-r4 -> 3.3.7-r2)
 13% █████████                                                                 (3/3) Upgrading libssl3 (3.3.2-r4 -> 3.3.7-r2)
 83% ██████████████████████████████████████████████████████████████            100% ██████████████████████████████████████████████████████████████████████████OK: 107 MiB in 128 packages

Drop the -s to actually upgrade. On a real server you'd do this regularly, because updates include security fixes.

sudo apk upgrade

In the terminal

student@vulntech:~$ sudo apk upgrade
[sudo] password for student:
(1/3) Upgrading musl (1.2.5-r8 -> 1.2.5-r11)
  0%                                                                             5% ███                                                                        10% ███████                                                                   (2/3) Upgrading libcrypto3 (3.3.2-r4 -> 3.3.7-r2)
 13% █████████                                                                  13% ██████████                                                                 14% ██████████                                                                 15% ███████████                                                                16% ████████████                                                               21% ███████████████                                                            26% ███████████████████                                                        31% ███████████████████████                                                    36% ███████████████████████████                                                42% ███████████████████████████████                                            47% ███████████████████████████████████                                        52% ██████████████████████████████████████                                     57% ██████████████████████████████████████████                                 62% ██████████████████████████████████████████████                             68% ██████████████████████████████████████████████████                         73% ██████████████████████████████████████████████████████                     78% ██████████████████████████████████████████████████████████                 82% █████████████████████████████████████████████████████████████             (3/3) Upgrading libssl3 (3.3.2-r4 -> 3.3.7-r2)
 83% ██████████████████████████████████████████████████████████████             89% █████████████████████████████████████████████████████████████████          94% █████████████████████████████████████████████████████████████████████      99% █████████████████████████████████████████████████████████████████████████ 100% ██████████████████████████████████████████████████████████████████████████OK: 107 MiB in 128 packages

What's installed?

apk info with no name lists every installed package; pipe it through wc -l to count them, or grep to look for one:

apk info | wc -l
apk info | grep -i doc | head -n 3

In the terminal

student@vulntech:~$ apk info | wc -l
128
student@vulntech:~$ apk info | grep -i doc | head -n 3
apk-tools-doc
bash-doc
bzip2-doc

Which package owns this file?

You found a program at /usr/bin/pstree and want to know where it came from. apk info --who-owns (like dpkg -S on Ubuntu) tells you which package put a file there:

apk info --who-owns /usr/bin/pstree
apk info --who-owns /bin/bash

In the terminal

student@vulntech:~$ apk info --who-owns /usr/bin/pstree
/usr/bin/pstree is owned by psmisc-23.7-r0
student@vulntech:~$ apk info --who-owns /bin/bash
/bin/bash is owned by bash-5.2.37-r0

Think of it like this: Every file a package installs is on a receipt. --who-owns looks a file up on the receipts and tells you which package brought it; -L reads one package's whole receipt.

Tip: Found a command and want its manual, source and sister tools? --who-owns names the package, then apk info -L that package lists everything else it installed.

Remember: apk update then apk upgrade keep the system current (-s simulates). apk info lists what's installed, apk info --who-owns FILE says which package a file came from.

HOME LEARN COMMUNITY DASHBOARD
Practice terminal Starting…