System and users
uname
Print the kernel name, release and version, the hostname, and the machine hardware type.
uname [-asnrvmo]
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
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
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
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
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
demo
-n prints the network node name, the same value hostname prints; the sandbox's is demo.
Combine fields
uname -sr
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
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))"
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
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"
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 -pto detect the architecture. On Linux it is usuallyunknown;-mis the reliable field.Expecting
unameto identify the distribution.uname -aon Ubuntu, Debian and Fedora all sayLinux; read/etc/os-release.Trusting
uname -rinside 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-systemare GNU. macOS and BSDunameaccept the short letters-a -m -n -p -r -s -v.On macOS,
uname -pgives a real answer (armori386) anduname -mgivesarm64orx86_64; on Linux, stick to-m.uname -aon 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.
| Option | What it does |
|---|---|
-a, --all | Print all fields, skipping -p and -i when they are unknown. |
-s, --kernel-name | Print the kernel name (the default). |
-n, --nodename | Print the network node name (hostname). |
-r, --kernel-release | Print the kernel release. |
-v, --kernel-version | Print the kernel build version and date. |
-m, --machine | Print the machine hardware name, such as x86_64. |
-p, --processor | Print the processor type; often unknown on Linux. |
-i, --hardware-platform | Print the hardware platform; often unknown on Linux. |
-o, --operating-system | Print the operating system name, such as GNU/Linux. |
Related
hostnamePrint the system's host name, its short or fully qualified form, or its IP addresses.whoamiPrint the user name of the effective user ID the current process runs as.idPrint the user and group IDs of the current user or of a named user.statShow a file's metadata (size, permissions, owner, inode, timestamps), or print chosen fields in your own format.- The case statementMatching one value against glob patterns with case, alternatives with |, the default branch, fall-through with ;& and ;;&, and parsing options with case.
- ConditionalsHow if, elif, &&, || and ! decide using exit statuses, the three test syntaxes, guard clauses, and why `a && b || c` is not an if-else.