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.
unameuname -a — Print all available information: kernel name, hostname, kernel release, kernel version, machine, processor, hardware platform, and OS.
uname -auname -r — Print the kernel release (version number). Useful for checking which kernel is running.
uname -runame -m — Print the machine hardware name (architecture). Common values: x86_64, aarch64, arm64.
uname -mAll Flags
uname -s — Print the kernel name (OS name). Same as plain 'uname'. Example output: Linux, Darwin.
uname -suname -n — Print the network node hostname. Same as 'hostname'.
uname -nuname -r — Print the kernel release. Example: 6.6.87-microsoft-standard-WSL2.
uname -runame -v — Print the kernel version (build date and number, not the release number).
uname -vuname -m — Print the machine hardware name (CPU architecture). Example: x86_64, aarch64.
uname -muname -p — Print the processor type. May output 'unknown' on some systems.
uname -puname -i — Print the hardware platform. May output 'unknown' on some systems (Linux-specific).
uname -iuname -o — Print the operating system name. Example: GNU/Linux (a GNU coreutils flag; not available on the BSD uname shipped with macOS).
uname -oCombining Flags
uname -sr — Print OS name and kernel release. Short combined form.
uname -sruname -mrs — Print machine, kernel release, and OS name.
uname -mrsuname -snr — Print OS name, hostname, and kernel release.
uname -snrPractical 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,2Related Tools
hostnamectl — Show or set system hostname and related settings. More detailed than uname on systemd systems.
hostnamectllsb_release -a — Show Linux distribution information (distro name, version, codename).
lsb_release -acat /etc/os-release — Show distribution information from the OS release file. Available on all modern Linux systems.
cat /etc/os-releasearch — 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
- GNU Coreutils manual: uname – official reference for every flag
- man7.org: uname(1) – the Linux manual page for uname
Related Commands
- 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