Linux commands
Browse topics

Identifying the system with uname and os-release

Version
unversioned
Review
Draft

Summary#

uname reports the kernel name, release and machine architecture. The file /etc/os-release identifies the distribution.

Syntax#

sh
uname -a
uname -r
uname -m
cat /etc/os-release
. /etc/os-release && echo "$ID $VERSION_ID"

-r prints the kernel release and -m the machine type, such as x86_64 or aarch64. The os-release file holds shell-style assignments.

Example#

sh
(
  set -eu
  uname -s
  test -n "$(uname -r)" && echo 'kernel release is available'
  . /etc/os-release
  test -n "$ID" && echo 'distribution ID is available'
)

Expected output#

Release numbers and IDs differ between systems, so the script checks that they exist.

Text
Linux
kernel release is available
distribution ID is available

Common mistakes#

The kernel release does not identify the distribution. In a container, uname -r shows the host or virtual machine kernel while /etc/os-release describes the container image. Architecture names vary between tools, for example aarch64 and arm64, so map them explicitly in install scripts. Test for a capability or a command when you can, instead of comparing version strings.

Version applicability#

This entry describes uname from GNU Coreutils and the os-release file used by current distributions.

Sources#

Attribution
DevLookup contributors
License
CC-BY-4.0