>_cmd.script

uname

Display Linux kernel and system information

System

By CMD Script Team · 3 min read · Last updated

SYNTAX
uname [OPTIONS]

Options

Command options and flags
FlagDescription
-aPrint all available system information (kernel name, hostname, release, version, machine, OS)
-sPrint the kernel name (default with no options)
-rPrint the kernel release, e.g. 6.8.0-45-generic
-vPrint the kernel version/build string
-mPrint the machine hardware name, e.g. x86_64
-nPrint the network node hostname
-oPrint the operating system name, e.g. GNU/Linux

Distribution compatibility

  • Ubuntu
  • Debian
  • Fedora
  • Arch
  • macOS (BSD uname, supports -a/-r/-m but not -o)

What it does

uname (short for "Unix name") prints information about the currently running kernel and system, such as the kernel name, release version, build details, and machine hardware architecture. It's one of the fastest ways to answer "what kernel and architecture am I running?" without opening any files. On its own, with no arguments, it just prints the kernel name (Linux).

Beginner examples

  • uname — print the kernel name (usually just Linux)
  • uname -r — print the kernel release, e.g. 6.8.0-45-generic
  • uname -m — print the machine hardware architecture, e.g. x86_64
  • uname -n — print the network hostname
uname -r

Advanced examples

  • Get a full one-line system summary: uname -a
  • Check architecture before downloading a binary: uname -m (e.g. aarch64 vs x86_64)
  • Script a kernel-version gate: [ "$(uname -r | cut -d. -f1)" -ge 5 ] && echo "modern kernel"
  • Combine with distro info for full context: uname -a; cat /etc/os-release
  • Check the OS name field specifically on Linux: uname -o
uname -a

Common mistakes

  • Assuming uname -a reveals the distribution (Ubuntu, Fedora, etc.) — it only reports kernel-level details, not distro branding.
  • Using uname -o on macOS and being surprised it fails — BSD uname doesn't support that flag; use sw_vers on macOS instead.
  • Parsing the free-form uname -a string with fragile regex in scripts instead of using the single-purpose flags (-r, -m, -s) that are stable and easy to parse.
  • Confusing kernel release (uname -r) with kernel version/build (uname -v) — they report different things.

Tips

  • Use uname -r in scripts that need to gate behavior on kernel version rather than parsing uname -a.
  • Pair uname -m with package manager checks when building or downloading architecture-specific software.
  • On systems without lsb_release, cat /etc/os-release is the standard fallback for distro identification.

Best practices

  • Prefer single-letter flags like -r or -m over parsing uname -a in automation — the full string's format isn't guaranteed to stay consistent across distros.
  • Combine uname -r with uname -m when filing bug reports or support tickets so the exact kernel and architecture are unambiguous.
  • Don't rely on uname alone to identify the Linux distribution; use it strictly for kernel/architecture facts and pair it with /etc/os-release for the rest.

Try it yourself

A simulated shell with a sample home directory — experiment freely, nothing leaves your browser. Type help to list supported commands.

Real-world use cases

  • Confirming which kernel version is running after a kernel update and reboot.
  • Determining CPU architecture before downloading a prebuilt binary or Docker image.
  • Including system details (uname -a) in bug reports or support requests.
  • Gating install scripts so they only run compiled binaries matching the detected architecture.

Common interview questions

  • What does uname -a show that uname -r doesn't? -a shows kernel name, hostname, release, version, machine architecture, and OS name; -r shows only the kernel release string.
  • Can uname tell you the Linux distribution? No — it reports kernel-level info only; distro name/version comes from lsb_release -a or /etc/os-release.
  • How would you script a check for 64-bit architecture? [ "$(uname -m)" = "x86_64" ] or check for aarch64 on ARM systems.

Frequently Asked Questions

What's the difference between uname -a and uname -r?

uname -a prints everything at once (kernel name, hostname, release, version, machine, and OS), while uname -r prints only the kernel release string, which is useful for scripts that need just the version number.

Does uname tell me my Linux distribution name?

No. uname reports kernel information, not distro branding — it will say Linux regardless of whether you're on Ubuntu, Fedora, or Arch. Use lsb_release -a or cat /etc/os-release for distro name and version.

Why does uname -m matter when downloading software?

It prints the CPU architecture (x86_64, aarch64, armv7l, etc.), which tells you which binary or package build to download for your machine.

Cheat sheet

Download a quick-reference cheat sheet for uname.