Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

uname

Show the name and version of the kernel, the machine type and the hostname.

Niveau
Dagelijks Linux
Groep
Systeeminformatie
Root nodig
Nee
Pakket
coreutils

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

uname prints facts about the running kernel and the hardware type. It is the quickest way to answer "which kernel runs here?" and "is this a 64-bit Intel/AMD or an ARM machine?".

Without options it prints only the kernel name (Linux). With -r you get the kernel release, which you need when you install kernel modules, read security bulletins or check that a kernel update is really active after a reboot.

Zo schrijf je het

uname [OPTION]...

Opties 11

Meest gebruikt

-a, --all
Print everything below, in this order (unknown fields are left out).
-s, --kernel-name
The kernel name (Linux). This is the default.
-n, --nodename
The network name of the machine (the hostname).
-r, --kernel-release
The kernel release, like 6.12.0-55.el10.x86_64.
-v, --kernel-version
The build version and date of the kernel.
-m, --machine
The hardware type, like x86_64 or aarch64.
-p, --processor
The processor type (often x86_64 or unknown).
-i, --hardware-platform
The hardware platform (often x86_64 or unknown).
-o, --operating-system
The operating system (GNU/Linux).
--help
Show help and exit.
--version
Show the version and exit.

Voorbeelden 11

$ als gewone gebruiker# als root (of met sudo)

  1. 1Show the running kernel release

    uname -r
    6.12.0-55.el10.x86_64

    el10 means a kernel for RHEL 10. The last part is the CPU architecture.

  2. 2Show all information on one line

    uname -a
    Linux server1.example.com 6.12.0-55.el10.x86_64 #1 SMP PREEMPT_DYNAMIC ... x86_64 GNU/Linux

    Paste this line in a bug report or a support ticket.

  3. 3Check the CPU architecture before you download software

    uname -m
    x86_64

    Download the x86_64 (amd64) build for this machine, or the aarch64 (arm64) build for an ARM server.

  4. 4Compare the running kernel with the installed kernels

    uname -r
    rpm -q kernel

    If the newest installed kernel is not the one that runs, the server still needs a reboot to use the update.

  5. 5Find out if a reboot is needed after updates

    [ "$(uname -r)" = "$(rpm -q --last kernel | head -1 | awk '{print $1}' | sed 's/^kernel-//')" ] || echo "reboot needed"

    A simple check for a patch script: the running kernel must be the newest installed one.

  6. 6Use the kernel release in a path

    ls /lib/modules/$(uname -r)/kernel/drivers/net/

    Kernel modules are stored in a folder named after the kernel release.

  7. 7Print only the hostname

    uname -n
    server1.example.com

    Same as the hostname command. Useful in log lines of scripts.

  8. 8Pick the right binary in an install script

    case "$(uname -m)" in x86_64) ARCH=amd64 ;; aarch64) ARCH=arm64 ;; *) echo "unknown arch"; exit 1 ;; esac

    Many tools (kubectl, terraform, trivy) name their downloads amd64 or arm64.

  9. 9Check the kernel version in an inventory report

    echo "$(hostname),$(uname -r),$(uname -m)" >> /tmp/inventory.csv

    Collect one line per server, then compare kernel versions across the fleet.

  10. 10Show the kernel build date

    uname -v

    A very old build date on an internet-facing server is a warning sign: patches are missing.

  11. 11Check the operating system family in a portable script

    [ "$(uname -s)" = "Linux" ] && echo "running on Linux"

    On macOS uname -s prints Darwin. Scripts that run on both can branch on this.

Let op

  • uname shows the running kernel, not the newest installed one. After a kernel update, uname -r changes only after a reboot.
  • -p and -i often print unknown. Use -m for the architecture.
  • The distribution version (RHEL 10.0) is not in uname. Read /etc/redhat-release or /etc/os-release.

Bestanden

/proc/sys/kernel/osrelease
The kernel release (same as uname -r).
/proc/version
The full kernel version string.
/etc/os-release
Name and version of the Linux distribution.

Tips om te onthouden

  • r = release (the kernel version you check most), m = machine (the CPU type), a = all.
  • Kernel = uname -r; distribution = cat /etc/redhat-release.