uname command in Linux with examples

The uname command in Linux is one of the frequently used commands. On Linux systems, there are a multitude of commands that can be used to print system information. We cover many of these commands in our guide about getting to know the hardware of your Linux box. One such command would be uname, which is especially good for listing information about the operating system itself and the Linux kernel that is running.

In this guide, you will learn about the uname command and get to know its various options that can be used to display certain kinds of information about your system. Follow along with the examples below to see how it works.

In this tutorial you will learn:

  • How to use the uname command on Linux

"<yoastmark

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software uname
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Frequently Used Options

The uname command shows information about the operating system, distribution name, and kernel version. Take a look at some of the examples below to see how the uname command in Linux actually works.

Keep in mind that some distributions may not display the same amount of information as others. For example, some distros may display the name or code name of the distribution in the uname output, while others will simply say “Linux.” It just depends on the how the developers listed that information.

uname command in Linux Basic Examples

  1. Running the uname command in Linux by itself is the same as specifying the -s or --kernel-name option. It should return the name of your kernel, but will omit additional information like the version number.
    $ uname
    Linux
    

    Erm, well. That’s not very useful, is it? The output tells us that we’re running a Linux kernel, which I hope for your own sake that you already knew that. Then again, if you just SSH’d into a terminal and need to quickly determine whether the system is running Linux, BSD, or Unix, this command could actually come in handy.

  2. To see all of the information that uname is capable of giving us, use the -a or --all option in your command.
    $ uname -a
    Linux linuxconfig 5.8.0-59-generic #66~20.04.1-Ubuntu SMP Thu Jun 17 11:14:10 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
    

    This output tells us that we’re running Linux, our hostname is linuxconfig, our kernel version and release is 5.8.0-59-generic, and that we’re running Ubuntu version 20.04.1. It also gives us the time when the kernel was compiled and tells us the kernel architecture (x86_64). The operating system itself is labelled as GNU/Linux. As mentioned before, keep in mind that this information could vary slightly from system to system – for example, the distribution name is often omitted.

  3. The only problem with the -a option with the unmane command in Linux is that it gives us a bunch of unorganized information. And oftentimes we’ll only need one piece of that info, such as the kernel version. Fortunately, uname includes a bunch more switches that allows us to isolate only the information that we need. One such example would be the -r or --kernel-release option, which only displays information about the kernel release.
    $ uname -r
    5.8.0-59-generic
    
  4. Use the -v or --kernel-version option to print information about the kernel version.
    $ uname -v
    #66~20.04.1-Ubuntu SMP Thu Jun 17 11:14:10 UTC 2021
    
  5. Use the -o or --operating-system option to display information about the operating system only. On Linux, this will pretty much always return output as “Linux” or “GNU/Linux”.
    $ uname -o
    GNU/Linux
    
  6. Use the -n or --nodename option to print your system’s hostname.
    $ uname -n
    linuxconfig
    
  7. Use the -m or --machine option to print your system’s CPU architecture.
    $ uname -m
    x86_64
    

"Various

NOTE
You can always use the man command to read more about the uname command and its official documentation. Click the previous link to see how to open the manual pages for any command on a Linux system.

Advanced Usage

The commands above covered some of the most frequently used options for the uname command. Since it’s a basic command that is simply used to print out system information, there’s not a lot of advanced things you can use it for. However, there are a couple of things you might be interested to know about this command.

uname command in Linux Basic Examples

  1. Keep in mind that you can use multiple options at the same time with uname. For example, if you wanted to list the hostname and kernel release information, you could use -r and -n in conjunction.
    $ uname -n -r
    OR
    $ uname -nr
    linuxconfig 5.8.0-59-generic
    
  2. The uname command is sometimes used in update commands, because it’s a very quick way to list your system’s kernel version. Just as an example, this command can be used to update the kernel headers for the currently running kernel on Red Hat based systems.
    $ sudo dnf install "kernel-headers-`uname -r`"
    

    This is not essential to know or anything. But it’s nice to keep in mind what’s happening in that command, as you are likely to come across various guides that recommend running a similar command that utilizes the output from uname.

Closing Thoughts

In this guide, we learned all about the uname command on Linux. The uname command provides us some essential information about our system. If you find some of the switches difficult to remember or simply irrelevant, the only thing you need to know for sure is that the -a option will list all the information. From there, you can simply sift through the relatively small output to glean the information you need.