Using uname command in Linux [Output Explained]

Ezra UNIX/Linux

<div class="paragraph"> <p>The uname stands for Unix Name and this useful command provides users with important system information.</p> </div> <div class="paragraph"> <p>In this quick tutorial, I’ll show what kind of information you can get about your system with the uname command.</p> </div> <div class="sect1"> <h2 id="_using_the_uname_command_on_linux">Using the uname command on Linux</h2> <div class="sectionbody"> <div class="paragraph"> <p>There are several options that can filter out the specific information you need.</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-sh" data-lang="sh">uname [options]</code></pre> </div> </div> <div class="paragraph"> <p>This command is really self-explanatory, so I will list the possible options and the description of their output.</p> </div> <div class="paragraph"> <p>Then I will go through each on my machine and display the output. Feel free to follow along.</p> </div> <div class="sect2"> <h3 id="_the_uname_command_options">The uname command Options</h3> <table class="tableblock frame-all grid-all stretch"> <colgroup> <col style="width: 50%;"> <col style="width: 50%;"> </colgroup> <thead> <tr> <th class="tableblock halign-left valign-top">Function</th> <th class="tableblock halign-left valign-top">Shortcut</th> </tr> </thead> <tbody> <tr> <td class="tableblock halign-left valign-top"><p class="tableblock">Kernel Name</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">\-s</p></td> </tr> <tr> <td class="tableblock halign-left valign-top"><p class="tableblock">Kernel Release</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">\-r</p></td> </tr> <tr> <td class="tableblock halign-left valign-top"><p class="tableblock">Kernel Version\*</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">\-v</p></td> </tr> <tr> <td class="tableblock halign-left valign-top"><p class="tableblock">Network Node Name (Hostname)</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">\-n</p></td> </tr> <tr> <td class="tableblock halign-left valign-top"><p class="tableblock">Machine architecture</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">\-m</p></td> </tr> <tr> <td class="tableblock halign-left valign-top"><p class="tableblock">Processor architecture</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">\-p</p></td> </tr> <tr> <td class="tableblock halign-left valign-top"><p class="tableblock">Hardware Platform (OS architecture)</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">\-i</p></td> </tr> <tr> <td class="tableblock halign-left valign-top"><p class="tableblock">Operating System</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">\-o</p></td> </tr> </tbody> </table> </div> <div class="sect2"> <h3 id="_the_uname_command_output">The uname command output</h3> <div class="paragraph"> <p>I’ve called each option to show you the output on my system.</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-sh" data-lang="sh">ezra@pop-os:~$ uname -s Linux

ezra@pop-os:~$ uname -r 5.3.0-22-generic

ezra@pop-os:~$ uname -v #24+system76157365947519.04~26b2022-Ubuntu SMP Wed Nov 13 20:0

ezra@pop-os:~$ uname -n kubuntu

ezra@pop-os:~$ uname -m x86_64

ezra@pop-os:~$ uname -p x86_64

ezra@pop-os:~$ uname -i x86_64

ezra@pop-os:~$ uname -o GNU/Linux</code></pre> </div> </div> <div class="paragraph"> <p>The output for -m,-p, and -i is the same on my system but these values don’t reference the same piece of information. If it was a 32-bit system, the output would be different.</p> </div> <div class="paragraph"> <p>You might also get different output if you are using a virtual machine. One one of mine, <code>-p</code> and <code>-i</code> return “unknown”.</p> </div> <div class="paragraph"> <p>Here’s an example using an old Ubuntu VM.</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-sh" data-lang="sh">ezra@ubuntu: ~$ uname -p unknown ezra@ubuntu: ~$ uname -i unknown</code></pre> </div> </div> </div> <div class="sect2"> <h3 id="_put_it_all_together_with_uname_a">Put it all together with uname -a</h3> <div class="paragraph"> <p>There is one more option. What if you just want a single string with all of this info? Yup, you can do that with <code>-a</code>!</p> </div> <div class="paragraph"> <p>Here’s the result of uname <code>-a</code> command:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-sh" data-lang="sh">ezra@pop-os:~$ uname -a Linux pop-os 5.3.0-22-generic #24+system76157365947519.04~26b2022-Ubuntu SMP Wed Nov 13 20:0 x86_64 x86_64 x86_64 GNU/Linux</code></pre> </div> </div> <div class="paragraph"> <p>Let’s break down the output one more time:</p> </div> <div class="ulist"> <ul> <li> <p><code>Linux</code> – OS kernel name</p> </li> <li> <p><code>pop-os</code> – hostname</p> </li> <li> <p><code>5.3.0-22-generic</code> – kernel release</p> </li> <li> <p><code>#24+system76157365947519.04~26b2022-Ubuntu SMP Wed Nov 13 20:0</code> – details about the last time the kernel was compiled</p> </li> <li> <p><code>x86_64</code> – Machine architecture</p> </li> <li> <p><code>x86_64</code> – Your processor architecture (<code>x86_64</code> means 64 bit)</p> </li> <li> <p><code>x86_64</code> – Your operating system’s architecture</p> </li> <li> <p><code>GNU/Linux</code> – Your operating system</p> </li> </ul> </div> <div class="paragraph"> <p>You may have this information available in different locations via the GUI, but nothing really beats the speed and ease of this simple command.</p> </div> <div class="paragraph"> <p>Now let me show you the most useful examples of this command.</p> </div> </div> <div class="sect2"> <h3 id="_get_the_kernel_version_with_uname_r">Get the kernel version with uname <code>-r</code></h3> <div class="paragraph"> <p>You can get the Linux kernel version information with the -r option:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-sh" data-lang="sh">ezra@pop-os:~$ uname -r 5.3.0-22-generic</code></pre> </div> </div> </div> <div class="sect2"> <h3 id="_get_the_hostname_with_uname_n">Get the hostname with uname -n</h3> <div class="paragraph"> <p>There are ways to get the hostname in Linux. One of them is using the -n option of the uname command:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-sh" data-lang="sh">ezra@pop-os:~$ uname -n kubuntu</code></pre> </div> </div> </div> <div class="sect2"> <h3 id="_get_processor_architecture_32_bit_or_64_bit">Get processor architecture (32-bit or 64-bit)</h3> <div class="paragraph"> <p>While you don’t get detailed CPU info in Linux with uname, but you can surely find out if your CPU is 32 bit or 64 bit with the -p option.</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-sh" data-lang="sh">ezra@pop-os:~$ uname -p x86_64</code></pre> </div> </div> <div class="paragraph"> <p><code>x86_64</code> means 64-bit. <code>i686</code>, <code>i386</code> etc means 32-bit.</p> </div> </div> <div class="sect2"> <h3 id="_get_operating_system_architecture_32_bit_or_64_bit">Get operating system architecture (32-bit or 64-bit)</h3> <div class="paragraph"> <p>You can install 32-bit OS on a 64-bit CPU. So to find out the architecture of your OS, use <code>-i</code> option:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-sh" data-lang="sh">ezra@pop-os:~$ uname -i x86_64</code></pre> </div> </div> <div class="paragraph"> <p>You can of course utilize the rest of the uname option if the need be.</p> </div> </div> </div> </div> <div class="sect1"> <h2 id="_conclusion">Conclusion</h2> <div class="sectionbody"> <div class="paragraph"> <p>The unix name utility is particularly helpful when troubleshooting. Many times this will be one of the first things requested by a support team. Knowing the kernel version, OS, and basic hardware information is important to figuring out why a piece of software is not performing as expected.</p> </div> <div class="paragraph"> <p>By the way, if you want to know which Linux distribution you are using, just look into the content of the <code>/etc/os-release</code> file.</p> </div> <div class="paragraph"> <p>I hope you now know how to use the uname command in Linux. If you have questions or suggestions, please let me know.</p> </div> </div> </div>