Linux uname Command Examples (Get Kernel version, release, hostname, etc)

by Himanshu Arora on September 4, 2012

Sometimes it is required to quickly determine details like kernel name, version, hostname, etc of the Linux box you are using.

Even though you can find all these details in respective files present under the proc filesystem, it is easier to use uname utility to get these information quickly.

The basic syntax of the uname command is :

uname [OPTION]...

Now lets look at some examples that demonstrate the usage of ‘uname’ command.

uname without any option

When the ‘uname’ command is run without any option then it prints just the kernel name. So the output below shows that its the ‘Linux’ kernel that is used by this system.

$ uname
Linux

You can also use uname -s, which also displays the kernel name.

$ uname -s
Linux

Get the network node host name using -n option

Use uname -n option to fetch the network node host name of your Linux box.

$ uname -n
dev-server

The output above will be the same as the output of the hostname command.

Get kernel release using -r option

uname command can also be used to fetch the kernel release information. The option -r can be used for this purpose.

$ uname -r
2.6.32-100.28.5.el6.x86_64

Get the kernel version using -v option

uname command can also be used to fetch the kernel version information. The option -v can be used for this purpose.

$ uname -v
#1 SMP Wed Feb 2 18:40:23 EST 2011

Get the machine hardware name using -m option

uname command can also be used to fetch the machine hardware name. The option -m can be used for this purpose. This indicates that it is a 64-bit system.

$ uname -m
x86_64

Get the processor type using -p option

uname command can also be used to fetch the processor type information. The option -p can be used for this purpose. If the uname command is not able to fetch the processor type information then it produces ‘unknown’ in the output.

$ uname -p
x86_64

Sometimes you might see ‘unknown’ as the output of this command, if uname was not able to fetch the information on processor type.

Get the hardware platform using -i option

uname command can also be used to fetch the hardware platform information. The option -i can be used for this purpose. If the uname command is not able to fetch the hardware platform information then it produces ‘unknown’ in the output.

$ uname -i
x86_64

Sometimes you might see ‘unknown’ as the output of this command, if uname was not able to fetch the information about the platform.

Get the operating system name using the -o option

uname command can also be used to fetch the operating system name. The option -o can be used for this purpose.

For example :

$ uname -o
GNU/Linux

Get all the information using uname -a option

All the information that by far we have learned to access using different flags can be fetched in one go. The option -a can be used for this purpose.

$ uname -a
Linux dev-server 2.6.32-100.28.5.el6.x86_64 #1 SMP Wed Feb 2 18:40:23 EST 2011 x86_64 x86_64 x86_64 GNU/Linux

Unknown value in the uname output

While writing this article, I was a bit curious as to why the uname utility is returning ‘unknown’ for processor type(-p) and hardware platform(-i) on my laptop that is running Ubuntu. I researched a bit over this issue.

One explanation I found was that uname command uses the uname() function(man 2 uname) that reads all information from the following kernel structure :

struct utsname {
               char sysname[];    /* Operating system name (e.g., "Linux") */
               char nodename[];   /* Name within "some implementation-defined
                                     network" */
               char release[];    /* OS release (e.g., "2.6.28") */
               char version[];    /* OS version */
               char machine[];    /* Hardware identifier */
           #ifdef _GNU_SOURCE
               char domainname[]; /* NIS or YP domain name */
           #endif
           };

Since information on processor type and hardware platform is not present in this structure so uname command returns ‘unknown’ for them.

The other explanation that I found was that inside uname.c the handling of the -p option is like :

...
...
...
char const *element = unknown;
#if HAVE_SYSINFO && defined SI_ARCHITECTURE
{
  static char processor[257];
  if (0 <= sysinfo (SI_ARCHITECTURE, processor, sizeof processor))
    element = processor;
}
#endif
...
...
...

The macros HAVE_SYSINFO and SI_ARCHITECTURE are not defined anywhere in the kernel and hence unknown is returned. Same could be true for the option -i.

I am not sure about the exact problem but we can safely assume that the -p and -i options are not standard and merely extensions and hence should be avoided while using uname command in a script.


Linux Sysadmin Course Linux provides several powerful administrative tools and utilities which will help you to manage your systems effectively. If you don’t know what these tools are and how to use them, you could be spending lot of time trying to perform even the basic administrative tasks. The focus of this course is to help you understand system administration tools, which will help you to become an effective Linux system administrator.
Get the Linux Sysadmin Course Now!

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

{ 3 comments… read them below or add one }

1 Ethan September 5, 2012 at 1:11 am

good. also leave a question to other users.

2 Jalal Hajigholamali September 5, 2012 at 9:43 pm

Hi,

Thanks a lot….

3 Ali December 25, 2013 at 6:50 pm

Hi Ramesh,
First of all, thank you for all your lessons, they are great.

I have a question if I may about Linux kernel and processor,
If the output of uname -imp are all related to the hardware, then what is the best way to tell if the kernel is 32bit or 64bit?

Most linux forums indicate that uname -imp outputs kernel info, but the manpage for uname suggests they are hardware info.

Thank you in advance.

Regards,
Ali Hussain
Sydney.

Leave a Comment

Previous post:

Next post: