opscape

System and users

uname

Print the kernel name, release and version, the hostname, and the machine hardware type.

uname [-asnrvmo]

10 of 10 examples run in Debian 13.7 on 2026-10-31 · coreutils 9.7-3 · manual: uname(1)

uname reports what the running kernel says about itself: its name (Linux, Darwin, FreeBSD), release, build version, the node name (hostname) and the CPU architecture. With no options it prints just the kernel name, which is exactly what a portable script needs to branch on.

It tells you about the kernel, not the distribution. To learn that a machine runs Debian 13 or Ubuntu 24.04, read /etc/os-release. Inside a container, uname -r shows the host's kernel, because containers share it; the examples here run in a Debian container on an Ubuntu host, which is why uname -a shows an Ubuntu kernel build.

Examples

Print the kernel name

uname
explain
output
Linux

Plain uname is the same as uname -s. This is the value to test in scripts that must behave differently on Linux and macOS (Darwin).

Print everything at once

uname -a
explain
output
Linux demo 6.8.0-138-generic #138-Ubuntu SMP PREEMPT_DYNAMIC Fri Jul 31 22:41:49 UTC 2026 x86_64 GNU/Linux

Kernel name, hostname, release, build version, machine, and on GNU the operating system. This is the line bug reports ask for.

Show the kernel release

uname -r
explain
output
6.8.0-138-generic

The release identifies the exact kernel build. It is the name of the directory under /lib/modules that holds that kernel's modules, and the version to match when installing kernel headers.

Show the CPU architecture

uname -m
explain
output
x86_64

x86_64 here; ARM machines print aarch64 on Linux and arm64 on macOS. Use this to pick which release binary to download.

Show the hostname

uname -n
explain
output
demo

-n prints the network node name, the same value hostname prints; the sandbox's is demo.

Combine fields

uname -sr
explain
output
Linux 6.8.0-138-generic

Options can be clustered; fields always come out in a fixed order, whatever order you give them in.

See why -p is not the option you want

uname -p -i
explain
output
unknown unknown

On Debian and most Linux distributions the processor and hardware-platform fields are unknown. Use -m for the architecture instead.

Find the distribution, which uname does not tell you

. /etc/os-release; echo "$PRETTY_NAME (kernel $(uname -r))"
explain
output
Debian GNU/Linux 13 (trixie) (kernel 6.8.0-138-generic)

/etc/os-release is a shell-syntax file, so sourcing it sets NAME, VERSION_ID, PRETTY_NAME and friends. The distribution is Debian even though uname -a shows an Ubuntu kernel build, because the kernel belongs to the host.

Branch on the OS in a script

case "$(uname -s)" in
  Linux)  echo "using GNU stat"; stat -c '%s bytes' todo.txt ;;
  Darwin) echo "using BSD stat"; stat -f '%z bytes' todo.txt ;;
  *)      echo "unsupported: $(uname -s)" >&2; exit 1 ;;
esac
output
using GNU stat
62 bytes

The kernel name picks the right flavor of a tool whose options differ between GNU and BSD, here stat. The fallback branch fails loudly instead of guessing.

Map the architecture to a download name

case "$(uname -m)" in
  x86_64)        arch=amd64 ;;
  aarch64|arm64) arch=arm64 ;;
  *)             arch=unknown ;;
esac
echo "would download tool-linux-$arch.tar.gz"
output
would download tool-linux-amd64.tar.gz

Release pages usually say amd64 and arm64 while the kernel says x86_64 and aarch64, so install scripts translate between the two.

Common pitfalls

  • Using uname -p to detect the architecture. On Linux it is usually unknown; -m is the reliable field.

  • Expecting uname to identify the distribution. uname -a on Ubuntu, Debian and Fedora all say Linux; read /etc/os-release.

  • Trusting uname -r inside a container or WSL to describe the image. It reports the kernel the container runs on, which may be a different distribution entirely.

GNU vs BSD and macOS

The examples above ran the GNU/Linux version. These are the differences that matter on macOS and the BSDs (written from their documentation, not run here).

  • The long options (--kernel-name, --all) and -o/--operating-system are GNU. macOS and BSD uname accept the short letters -a -m -n -p -r -s -v.

  • On macOS, uname -p gives a real answer (arm or i386) and uname -m gives arm64 or x86_64; on Linux, stick to -m.

  • uname -a on macOS has no trailing operating-system field; its version string contains the XNU kernel build instead.

Options worth knowing

A selection, described in our own words. For the full list, see uname(1) or uname --help.

OptionWhat it does
-a, --allPrint all fields, skipping -p and -i when they are unknown.
-s, --kernel-namePrint the kernel name (the default).
-n, --nodenamePrint the network node name (hostname).
-r, --kernel-releasePrint the kernel release.
-v, --kernel-versionPrint the kernel build version and date.
-m, --machinePrint the machine hardware name, such as x86_64.
-p, --processorPrint the processor type; often unknown on Linux.
-i, --hardware-platformPrint the hardware platform; often unknown on Linux.
-o, --operating-systemPrint the operating system name, such as GNU/Linux.

Related