Linux+: Linux Shell 24 – System Information – uname

J

Jarret W. Buse

Guest
Linux+: Linux Shell 24 – System Information – uname

There are many times a user may need to find system information about the system hardware and Operating System (OS). The OS can be a very important factor since so many different distros of Linux exist.

The shell command used to find the hardware and Operating System information is 'uname'.

The command 'uname' stands for UNIX Name and the syntax is:

uname options

The options are as follows:

  • -s (--kernel-name) - Lists the kernel name of the operating system
Sample output: Linux

  • -n (--nodename) - Prints the network node hostname of the operating system
Sample output: jarret-Presario-CQ62-Notebook-PC

  • -r ( --kernel-release) - Displays the kernel release of the operating system
Sample output: 3.13.0-24-generic

  • -v (--kernel-version) - Prints the kernel version of the operating system
Sample output: #47-Ubuntu SMP Fri May 2 23:30:00 UTC 201

  • -m (--machine) - Lists the machine hardware name of the system
Sample output: x86_64

  • -p (--processor) - Prints the processor type of the computer or lists it as "unknown" if the kernel does not make the information readily available
Sample output: x86_64

  • -i (--hardware-platform) - Displays the hardware platform of the system or uses "unknown" if the kernel does not make the information readily available
Sample output: x86_64

  • -o (--operating-system) - Prints the operating system name
Sample output: GNU/Linux

  • --help - Shows help information for the uname command
  • --version - Outputs version information
Sample output:

uname (GNU coreutils) 8.21

Copyright (C) 2013 Free Software Foundation, Inc.

License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.

This is free software: you are free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law.

Written by David MacKenzie.


  • -a (--all) - prints all the optional information, except it omits the processor typeand the hardware platform name if they are unknown

Sample output: Linux jarret-Presario-CQ62-Notebook-PC 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

If the uname command is used with no options, the default option used is '-s' for the kernel name.

If multiple options are used, the output does not match the order of the options given in the command line. The output order defaults to the following:

  1. -s – kernel-name
  2. -n – nodename
  3. -r – kernel-release
  4. -v – kernel-version
  5. -m – machine
  6. -p – processor
  7. -i – hardware-platform
  8. -o – operating system

To explain this point further, let's assume the following command were to be executed:

uname -prno

The user is requesting the processor, kernel release, nodename and operating system information. Even though the options were typed in a specific order, the output would still be nodename, kernel release, processor and operating system (-nrpo).

To illustrate, the command would output the following on my system:

jarret-Presario-CQ62-Notebook-PC 3.13.0-24-generic x86_64 GNU/Linux

The individual output is as listed:

  • -n – jarret-Presario-CQ62-Notebook-PC
  • -r – 3.13.0-24-generic
  • -p – x86_64
  • -o – GNU/Linux
Let's use the uname command as an example to learn a little more about using the command line.

In a terminal, you can use a single exclamation mark (!) or double exclamation marks (!!) to run previous commands.

Starting with the double exclamation marks, it is used to run the last command again. For example, if we ran the command 'uname -n' and we wanted to run it again, just type “!!” and press enter.

The output would show a line with the previous command and then the output of the command should follow that line. Of course, with most shells you can use the up and down arrow to scroll though the history.

Now, assume we wanted to add more options, such as “-p”, to the previous command. We can type “!! -p” and press enter to get the same result as typing “uname -n -p”.

It is also possible to redirect the command output to a file or other command. In this case, we will output it to a file. The command would be “!! > uname.txt”. Of course, the filename can be any name you want and include a path to place it in another location.

The single exclamation mark (!) is used to show or run the previous command. The difference is that you can specify which command should be found in the command history. The syntax is “![command][:p]”.

NOTE: Be aware that there is no space between the exclamation mark and the command name as well the command name and the “:p”.

If I wanted to run the last uname command in the command history, I would run “!uname”. The output would show the last uname command with options and other parameters such as redirection and the like. The command would be executed again to show the output. If you wanted to see only the last uname command, you would type “!uname:p” and only that command would be displayed without executing the command again.

Do not overlook this command quite yet. Let's say you had used a command before which may have been executed previously a few hours or even days. In the meantime, you have used other commands and you do not want to spend the time scrolling through the history. For example, if I had used the command “man” to look up a command and I wanted to go back to it, I would type “!man”. The last “man” command entered would be run again.

Keep in mind that there are many commands and many shortcuts in the shell terminal. Practice the commands and know them before you take a Linux+ exam.
 

Attachments

  • slide.jpg
    slide.jpg
    49.4 KB · Views: 36,315

Staff online

Members online


Top