Skip to content
FLAVIO COPES
flaviocopes.com

Linux commands: uname

By

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

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 command output displaying x86_64 i386 for hardware and processor architecture

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

uname -srv

Terminal showing uname -srv command output with Darwin OS name, kernel version 19.6.0, and build details

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

Terminal showing uname -n command output displaying mbp.local as the network node name

The -a option prints all available fields:

Terminal showing uname -a command output with all system information including Darwin, hostname, version, and architecture

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.

Terminal showing sw_vers command output displaying Mac OS X version 10.15.6 with build version 19G2021

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

Tagged: CLI · All topics
~~~

Related posts about cli: