Linux Command uname Usage and 9 Options

The Linux command uname is used to check essential system information, such as the kernel version and system architecture. In this post, we will explore the basic usage of the uname command and its options, and explain how it can be practically applied in everyday situations.

What is the Linux command uname?

uname stands for “Unix Name” and is a Linux command that prints information about the current system. It is commonly used to check details such as the kernel version, system architecture, and operating system name.

Basic Usage

The basic format of the uname command is as follows. When this command is entered, only the kernel name is printed.

uname
ShellScript

In the case of an Ubuntu 24.04 operating system, the output will simply be “Linux.” For more detailed information, various options can be used in combination with this command.

Figure 1. Linux command uname: displaying kernel name
Figure 1. Linux command uname: displaying kernel name

uname Command Options

The uname command provides several options to retrieve more specific information about the system. Let’s look at each option and how to use it.

-a (Display All Information)

The -a option stands for “all,” and it outputs all system information at once.

uname -a
ShellScript

When using the -a option, as shown below, the kernel name, network node hostname, kernel release, kernel version, hardware name, processor type, hardware platform, and operating system name are displayed in sequence.

Figure 2. Linux command uname: displaying all information with the -a option
Figure 2. Linux command uname: displaying all information with the -a option

This makes the -a option very useful as it allows you to view all major system information at once.

-s (Kernel Name)

The -s option prints the kernel name. On most Linux systems, the output will be “Linux.”

uname -s
ShellScript

-n (Hostname)

The -n option displays the system’s network node hostname. As the name suggests, the hostname is used to identify the system on a network.

uname -n
ShellScript

-r (Kernel Release)

The uname -r command prints the release number of the currently running kernel. The kernel release information can be used to determine whether an update is needed. For example, when a new CPU is released, you can check the kernel release to see if it supports the new processor.

uname -r
ShellScript

The -r option is one of the most frequently used options with uname, and it displays the kernel release information as shown below.

Figure 3. Linux command uname: checking kernel release information with the -r option
Figure 3. Linux command uname: checking kernel release information with the -r option

-v (Kernel Version)

The -v option prints the version information of the kernel. The kernel version can impact system performance and stability, so it’s important to check this information when issues arise.

uname -v
ShellScript

-m (Machine Hardware Name)

The -m option prints the hardware architecture of the system. For example, on a 64-bit system, the output will be x86_64, and on a 32-bit system, it will be i686. This information is often referenced during program compilation or installation.

uname -m
ShellScript

-p (Processor Type)

The -p option prints the processor type of the system. However, it may return “unknown” on some Linux systems if not supported.

uname -p
ShellScript

-i (Hardware Platform)

The -i option prints the hardware platform of the system. Similar to the -p option, it may return “unknown” if the system doesn’t support this option.

uname -i
ShellScript

-o (Operating System Name)

This option prints the name of the operating system currently running on the system. On most Linux systems, the output will be “GNU/Linux.”

uname -o
ShellScript

Useful Applications: Using uname in Scripts

Although the uname command is simple by itself, it can be quite useful when combined with other commands in scripts. For instance, you can write a script that only runs on a specific kernel version by checking the kernel version with uname -r and controlling the behavior accordingly.

#!/bin/bash
if [[ $(uname -r) == "5.4.0-42-generic" ]]; then
    echo "Running the script on the specified kernel version."
else
    echo "Different kernel version. Terminating the script."
fi
ShellScript

As shown below, the kernel release is 6.8.0-45-generic, so the condition in the script does not match the checked kernel release 5.4.0-42-generic, and the else block is executed.

Figure 4. Example of using Linux command uname in a script
Figure 4. Example of using Linux command uname in a script

Precautions When Using uname

  • Check for Supported Options: Not all Linux distributions support every uname option. The -p and -i options may return “unknown” on some systems.
  • No Root Privileges Required: The uname command does not require root privileges, so anyone can use it to check system information. However, be cautious about exposing sensitive system information to others for security reasons.

Summary

The Linux command uname is one of the basic commands for quickly checking system information. It can output various details such as the operating system name, kernel version, and system architecture, making it an essential tool for system maintenance and troubleshooting. The -a option is especially useful as it allows you to view all system information at once, making it a frequently used command.

References

Leave a Comment