# 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.

Source: https://www.jpkc.com/db/en/cheatsheets/shell-system/uname/

<!-- PROSE:intro -->
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.
<!-- PROSE:intro:end -->

## Common Usage

`uname` — Print the OS name only. Usually outputs 'Linux', 'Darwin', or similar.

```bash
uname
```

`uname -a` — Print all available information: kernel name, hostname, kernel release, kernel version, machine, processor, hardware platform, and OS.

```bash
uname -a
```

`uname -r` — Print the kernel release (version number). Useful for checking which kernel is running.

```bash
uname -r
```

`uname -m` — Print the machine hardware name (architecture). Common values: x86_64, aarch64, arm64.

```bash
uname -m
```

## All Flags

`uname -s` — Print the kernel name (OS name). Same as plain 'uname'. Example output: Linux, Darwin.

```bash
uname -s
```

`uname -n` — Print the network node hostname. Same as 'hostname'.

```bash
uname -n
```

`uname -r` — Print the kernel release. Example: 6.6.87-microsoft-standard-WSL2.

```bash
uname -r
```

`uname -v` — Print the kernel version (build date and number, not the release number).

```bash
uname -v
```

`uname -m` — Print the machine hardware name (CPU architecture). Example: x86_64, aarch64.

```bash
uname -m
```

`uname -p` — Print the processor type. May output 'unknown' on some systems.

```bash
uname -p
```

`uname -i` — Print the hardware platform. May output 'unknown' on some systems (Linux-specific).

```bash
uname -i
```

`uname -o` — Print the operating system name. Example: GNU/Linux (a GNU coreutils flag; not available on the BSD uname shipped with macOS).

```bash
uname -o
```

## Combining Flags

`uname -sr` — Print OS name and kernel release. Short combined form.

```bash
uname -sr
```

`uname -mrs` — Print machine, kernel release, and OS name.

```bash
uname -mrs
```

`uname -snr` — Print OS name, hostname, and kernel release.

```bash
uname -snr
```

## Practical Examples & Scripts

`[ $(uname -s) = 'Linux' ] && echo Linux` — Detect Linux in a shell script. Useful for cross-platform scripts.

```bash
[ $(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.

```bash
[ $(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.

```bash
uname -r | grep -q 'WSL' && echo 'Running inside WSL'
```

`uname -r | cut -d. -f1,2` — Extract the major and minor kernel version numbers only.

```bash
uname -r | cut -d. -f1,2
```

## Related Tools

`hostnamectl` — Show or set system hostname and related settings. More detailed than uname on systemd systems.

```bash
hostnamectl
```

`lsb_release -a` — Show Linux distribution information (distro name, version, codename).

```bash
lsb_release -a
```

`cat /etc/os-release` — Show distribution information from the OS release file. Available on all modern Linux systems.

```bash
cat /etc/os-release
```

`arch` — Print the machine architecture. Equivalent to 'uname -m'.

```bash
arch
```

<!-- PROSE:outro -->
## 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](https://www.gnu.org/software/coreutils/manual/html_node/uname-invocation.html) – official reference for every flag
- [man7.org: uname(1)](https://man7.org/linux/man-pages/man1/uname.1.html) – the Linux manual page for uname
<!-- PROSE:outro:end -->

## Related Commands

- [hostnamectl](https://www.jpkc.com/db/en/cheatsheets/shell-system/hostnamectl/) – show and set the hostname and system information on systemd
- [uptime](https://www.jpkc.com/db/en/cheatsheets/shell-system/uptime/) – show system uptime and load average
- [lsblk](https://www.jpkc.com/db/en/cheatsheets/shell-system/lsblk/) – list block devices and partitions as a tree

