uname — Print Kernel and System Information

Practical guide to uname: print kernel name, kernel release, hostname and CPU architecture – plus how it differs from distribution info.

uname is one of the first commands you run on an unfamiliar system: in seconds it reveals the kernel name, kernel release, hostname and CPU architecture. It is indispensable in scripts for branching on platform or architecture – for example when selecting the right binary for x86_64 or aarch64. This guide walks you through the key flags, useful combinations and where uname stops: the distribution details it deliberately does not provide.

Common Usage

uname — Print the OS name only. Usually outputs 'Linux', 'Darwin', or similar.

uname

uname -a — Print all available information: kernel name, hostname, kernel release, kernel version, machine, processor, hardware platform, and OS.

uname -a

uname -r — Print the kernel release (version number). Useful for checking which kernel is running.

uname -r

uname -m — Print the machine hardware name (architecture). Common values: x86_64, aarch64, arm64.

uname -m

All Flags

uname -s — Print the kernel name (OS name). Same as plain 'uname'. Example output: Linux, Darwin.

uname -s

uname -n — Print the network node hostname. Same as 'hostname'.

uname -n

uname -r — Print the kernel release. Example: 6.6.87-microsoft-standard-WSL2.

uname -r

uname -v — Print the kernel version (build date and number, not the release number).

uname -v

uname -m — Print the machine hardware name (CPU architecture). Example: x86_64, aarch64.

uname -m

uname -p — Print the processor type. May output 'unknown' on some systems.

uname -p

uname -i — Print the hardware platform. May output 'unknown' on some systems (Linux-specific).

uname -i

uname -o — Print the operating system name. Example: GNU/Linux (a GNU coreutils flag; not available on the BSD uname shipped with macOS).

uname -o

Combining Flags

uname -sr — Print OS name and kernel release. Short combined form.

uname -sr

uname -mrs — Print machine, kernel release, and OS name.

uname -mrs

uname -snr — Print OS name, hostname, and kernel release.

uname -snr

Practical Examples & Scripts

[ $(uname -s) = 'Linux' ] && echo Linux — Detect Linux in a shell script. Useful for cross-platform scripts.

[ $(uname -s) = 'Linux' ] && echo 'Running on Linux'

[ $(uname -m) = 'aarch64' ] && echo ARM — Detect ARM64 architecture (e.g. Apple Silicon, Raspberry Pi). Useful for selecting binaries.

[ $(uname -m) = 'aarch64' ] && echo 'ARM64 detected'

uname -r | grep -q 'WSL' && echo WSL — Detect Windows Subsystem for Linux (WSL) by checking the kernel release string.

uname -r | grep -q 'WSL' && echo 'Running inside WSL'

uname -r | cut -d. -f1,2 — Extract the major and minor kernel version numbers only.

uname -r | cut -d. -f1,2

hostnamectl — Show or set system hostname and related settings. More detailed than uname on systemd systems.

hostnamectl

lsb_release -a — Show Linux distribution information (distro name, version, codename).

lsb_release -a

cat /etc/os-release — Show distribution information from the OS release file. Available on all modern Linux systems.

cat /etc/os-release

arch — Print the machine architecture. Equivalent to 'uname -m'.

arch

Conclusion

uname is a pure read-only command – it changes nothing and is safe to drop into any script. For a quick overview uname -a is all you need; when you want individual values, reach for -r (kernel release, e.g. for matching drivers or kernel modules), -m (architecture such as x86_64 or aarch64) or -s/-n/-o. Keep one thing in mind: uname only knows the kernel, not the distribution. Which distro and version you are running is revealed by /etc/os-release, lsb_release or hostnamectl. On macOS uname is present too, but the actual macOS version comes from sw_vers.

Further Reading

  • hostnamectl – show and set the hostname and system information on systemd
  • uptime – show system uptime and load average
  • lsblk – list block devices and partitions as a tree