CrackOps
Interview PrepTracksLinuxAWS LabSoonInterview RoomSoon
Sign inStart free
CrackOps

Interview prep for the people who keep production up.

[email protected]
ProductInterview PrepTracksDashboardInterview Room
RolesDevOpsSREPlatformCloud
CompanyAboutContactPrivacyTerms
© CrackOps
Linux / System Information / uname

uname

Show the kernel name, version and architecture

Beginneressentialkernelsystem info

uname prints facts about the running kernel: its name, release, build, the hostname and the CPU architecture. You use it to pick the right binary to download (x86_64 or aarch64), check which kernel actually booted after an update, and fill in bug reports.

Syntaxuname [-a] [-s] [-n] [-r] [-v] [-m] [-o]

Watch it run

You've logged in to an unfamiliar server and want to know the kernel and architecture before doing anything else.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 3
uname

With no options uname prints only the kernel name. Not very useful on its own, but scripts use it to tell Linux from macOS (Darwin).

Anatomy of a command

$
commanduname

coreutils uname: one system call, then prints the fields you ask for, in a fixed order.

How it works

uname makes a single uname() system call, which fills a struct utsname with five strings: sysname (Linux), nodename (the hostname), release (the kernel version string), version (build number, flags such as SMP PREEMPT_DYNAMIC, and the build date) and machine (the architecture). The kernel keeps nodename in the UTS namespace, so inside a container uname -n shows the container's hostname, while release still shows the host's kernel, because containers share the host kernel. -o prints GNU/Linux, a string compiled into coreutils, not read from the kernel. -p and -i are not portable: Debian and Ubuntu patch them to print the architecture, other distributions print 'unknown'. The same data is in /proc/sys/kernel/{ostype,hostname,osrelease,version} and /proc/version.

Options you'll actually use

-aEverything: name, host, release, version, machine, (processor, platform), OS
-sKernel name (default with no options): Linux
-nNetwork node hostname (same as hostname)
-rKernel release: 6.8.0-86-generic
-vKernel build: #86-Ubuntu SMP PREEMPT_DYNAMIC and the build date
-mMachine architecture: x86_64, aarch64
-oOperating system: GNU/Linux
-p / -iProcessor / platform: non-portable, often 'unknown'

Common mistakes

Running uname -r after apt upgrade to confirm the new kernel

uname reports the kernel in memory. A newly installed kernel only runs after a reboot.

Compare uname -r with ls /boot/vmlinuz-*, or check /var/run/reboot-required
Using uname -m output directly in download URLs

Projects name architectures differently: uname says x86_64/aarch64, release pages often say amd64/arm64.

Map it in a case statement, or use dpkg --print-architecture
Relying on uname -p or uname -i in portable scripts

They are non-portable; many distributions print 'unknown'.

uname -m
Using uname inside a container to learn the container's OS version

uname reports the shared host kernel, not the image's distribution.

cat /etc/os-release

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Print only the kernel release and the machine architecture, on one line.

  2. 2

    Show the full uname output and find the hostname inside it.

  3. 3

    Compare the running kernel with the kernels installed in /boot. (In the practice sandbox /boot is empty: a container runs on the host's kernel and has none of its own, which is the point to notice.)

  4. 4

    Read the same release string straight from /proc.

Related commands

hostnameShow or set the system's host namelscpuShow CPU architecture, cores, threads and cachesuptimeHow long the system has run, and its load average
PrevioussuNexthostname
Linux / System Information / uname

uname

Show the kernel name, version and architecture

Beginneressentialkernelsystem info

uname prints facts about the running kernel: its name, release, build, the hostname and the CPU architecture. You use it to pick the right binary to download (x86_64 or aarch64), check which kernel actually booted after an update, and fill in bug reports.

Syntaxuname [-a] [-s] [-n] [-r] [-v] [-m] [-o]

Watch it run

You've logged in to an unfamiliar server and want to know the kernel and architecture before doing anything else.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 3
uname

With no options uname prints only the kernel name. Not very useful on its own, but scripts use it to tell Linux from macOS (Darwin).

Anatomy of a command

$
commanduname

coreutils uname: one system call, then prints the fields you ask for, in a fixed order.

How it works

uname makes a single uname() system call, which fills a struct utsname with five strings: sysname (Linux), nodename (the hostname), release (the kernel version string), version (build number, flags such as SMP PREEMPT_DYNAMIC, and the build date) and machine (the architecture). The kernel keeps nodename in the UTS namespace, so inside a container uname -n shows the container's hostname, while release still shows the host's kernel, because containers share the host kernel. -o prints GNU/Linux, a string compiled into coreutils, not read from the kernel. -p and -i are not portable: Debian and Ubuntu patch them to print the architecture, other distributions print 'unknown'. The same data is in /proc/sys/kernel/{ostype,hostname,osrelease,version} and /proc/version.

Options you'll actually use

-aEverything: name, host, release, version, machine, (processor, platform), OS
-sKernel name (default with no options): Linux
-nNetwork node hostname (same as hostname)
-rKernel release: 6.8.0-86-generic
-vKernel build: #86-Ubuntu SMP PREEMPT_DYNAMIC and the build date
-mMachine architecture: x86_64, aarch64
-oOperating system: GNU/Linux
-p / -iProcessor / platform: non-portable, often 'unknown'

Common mistakes

Running uname -r after apt upgrade to confirm the new kernel

uname reports the kernel in memory. A newly installed kernel only runs after a reboot.

Compare uname -r with ls /boot/vmlinuz-*, or check /var/run/reboot-required
Using uname -m output directly in download URLs

Projects name architectures differently: uname says x86_64/aarch64, release pages often say amd64/arm64.

Map it in a case statement, or use dpkg --print-architecture
Relying on uname -p or uname -i in portable scripts

They are non-portable; many distributions print 'unknown'.

uname -m
Using uname inside a container to learn the container's OS version

uname reports the shared host kernel, not the image's distribution.

cat /etc/os-release

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Print only the kernel release and the machine architecture, on one line.

  2. 2

    Show the full uname output and find the hostname inside it.

  3. 3

    Compare the running kernel with the kernels installed in /boot. (In the practice sandbox /boot is empty: a container runs on the host's kernel and has none of its own, which is the point to notice.)

  4. 4

    Read the same release string straight from /proc.

Related commands

hostnameShow or set the system's host namelscpuShow CPU architecture, cores, threads and cachesuptimeHow long the system has run, and its load average
PrevioussuNexthostname