Linux commands: uname

By

Published · Updated

Tagged: CLI

Learn how uname prints the kernel name, release, version, hostname, and machine hardware on Unix systems, and when macOS users should use sw_vers instead.

Running uname without an option prints the kernel name:

uname

Terminal showing uname command output displaying Darwin as the operating system name

On macOS this prints Darwin. On a Linux system it normally prints Linux.

The -m option prints the machine hardware name:

uname -m

On an Intel Mac or many Linux boxes you still see x86_64. On Apple silicon Macs you see arm64:

uname -m
# arm64

The -p option tries to print the processor type, but it is not portable and can print unknown. Prefer -m in scripts.

Terminal showing uname -mp output displaying arm64 arm for the machine hardware and processor type

Use -s for the kernel name, -r for its release, and -v for its version:

uname -srv

Terminal showing uname -srv output with the Darwin kernel name, release 27.2.0, and the kernel version and build details

The -n option prints the network node name, which is normally the hostname:

Terminal showing uname -n output displaying mac as the network node name

The -a option prints all available fields:

Terminal showing uname -a output with all the fields: Darwin, the hostname mac, release 27.2.0, the kernel version and arm64

On macOS, use sw_vers when you need the macOS product name, version, and build number. Those values differ from the Darwin kernel version printed by uname. This is the output on my Mac:

sw_vers
# ProductName:		macOS
# ProductVersion:		27.2.1
# BuildVersion:		26B131

Terminal showing sw_vers output displaying ProductName macOS, ProductVersion 27.2.1 and BuildVersion 26B131

The uname command works on Linux, macOS, WSL, and other Unix-like environments. Stick to -s, -n, -r, -v, and -m when portability matters.

Want me to talk about your product? You can sponsor this site.

Related posts about cli: