Linux System Information Commands

Linux System Information Commands

If you’re coming from Windows or macOS, you may be used used to easily finding system information about your machine via the GUI (graphical user interface).

Since you’ll probably interact with Linux via the command line most of the time, and will operate multiple machines, it’s good to know a few useful commands to know useful information about your system.

Objectives

In this tutorial we’ll cover a few commands that help us find information on our Linux system. We will cover some of the key commands – uname, uptime, hostname, date, w, and whoami.

Prerequisites

  • Access to a Linux machine.
  • Acting as a non-root sudo user to ensure a secure environment

The uname Command

Let’s assume that we don’t know the system name and want to find out. The easiest method to do is to type the following command:

uname

The uname command without any parameter or switch provides the type of operating system. For example, in this case, the output displays Linux, a type of operating system.

Output
Linux

Let’s print detailed information about the system. We can find all the relevant details about the Linux system with the help of the -a parameter.

uname -a

The -a parameter stands for all, which prints all details about the Linux operating system.

It prints the following details:

  • Kernel name
  • Hostname
  • Kernel release date
  • Kernel version
  • Hardware architecture
  • Type of operating system
Output of uname -a
Linux bytexd 5.8.0-63-generic #71~20.04.1-Ubuntu SMP Thu Jul 15 17:46:08 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Various other parameters can be used with the uname command. We can get the details of these parameters with the following command:

uname --help
Output
Usage: uname [OPTION]...
Print certain system information.  With no OPTION, same as -s.

  -a, --all                print all information, in the following order,
                             except omit -p and -i if unknown:
  -s, --kernel-name        print the kernel name
  -n, --nodename           print the network node hostname
  -r, --kernel-release     print the kernel release
  -v, --kernel-version     print the kernel version
  -m, --machine            print the machine hardware name
  -p, --processor          print the processor type (non-portable)
  -i, --hardware-platform  print the hardware platform (non-portable)
  -o, --operating-system   print the operating system
      --help     display this help and exit
      --version  output version information and exit

GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Full documentation at: <https://www.gnu.org/software/coreutils/uname>
or available locally via: info '(coreutils) uname invocation'

When we run this command, we get the list of all available parameters along with their description. We can test each of the parameters with the uname command. For example, we can find out the system name with the following command:

This is what each of the other parameters prints on my machine:

$ uname -s (print the kernel name)
Linux

$ uname -n (print the network node hostname)
bytexd

$ uname -r (print the kernel release)
5.8.0-63-generic

$ uname -v (print the kernel version)
​#71~20.04.1-Ubuntu SMP Thu Jul 15 17:46:08 UTC 2021

$ uname -m (print the machine hardware name)
x86_64

$ uname -p (print the processor type (non-portable))
x86_64

$ uname -i (print the hardware platform (non-portable))
x86_64

$ uname -o (print the operating system)
GNU/Linux

The uptime Command

Let’s assume we want to know how long the system has been up and running. We also want to know the load average on the system. This might be useful when we want to perform certain maintenance tasks on the system, or we need to perform an audit on the system. There could also be other reasons due to which we need to know the uptime and load on the system.

To find this information, we can use the uptime command in the following manner:

uptime

We need to enter the uptime command without any parameters. The output of this command displays the number of users and time since the system has been up and running.

Output
02:28:50 up 18 min,  1 user,  load average: 0.01, 0.04, 0.12
It’s 2:28 AM in my time, and my Linux machine has been running for about 18 minutes.

If you need to find information on all available parameters, we need to use the following command:

uptime --h
Output
Usage:
 uptime [options]

Options:
 -p, --pretty   show uptime in pretty format
 -h, --help     display this help and exit
 -s, --since    system up since
 -V, --version  output version information and exit

For more details see uptime(1).

Let’s verify the date and time since the system has been up. To do this, we need to execute the following command:

uptime -s
Date and Time Stamps
021-07-30 02:10:47

The hostname Command

We can also find the hostname of the Linux host, which is Ubuntu in this case. Let’s execute the following command:

hostname
Output
bytexd

The output displays the hostname. We can get the same output with another command:

cat /etc/hostname
Output
bytexd

This command also displays the hostname. When talking about the hostname, the question that comes to mind is can we change the hostname of the Ubuntu system? The answer is Yes. We can change the hostname. We have to change the name in the /etc/hostname file, which can be edited using any text editor, such as the nano editor.

After we edit the /etc/hostname file and assign a new name to the host, we need to save the file and restart the system for the hostname change to take effect.

Let’s find the IP address(es) associated with the system. We need to execute the following command:

hostname -i
Output
192.168.1.2 fe80::b2d5:6bb6:439:35aa

The output of this command displays the IPv4 and IPv6 assigned to the system. It is important to note that the IPv6 format is completely different from the IPv4 format, which is easy to understand. For example, you can understand the numbers in four octets: 192.168.1.2. however, when we refer to an IPv6 address it is difficult to interpret.

For example, an IPv6 address is: fe80::b2d5:6bb6:439:35aa. It is a difficult to understand format. We may cover IPv6 in another article as it is beyond the scope of this one.

Let’s now try to find out all IPv4 addresses assigned to the system by executing the following command:

hostname -I
Output
192.168.1.2

There is a difference between -i and -I. The -i parameter displays the associated IPv4 and IPv6 addresses of the system.

The -I parameter displays all IPv4 addresses associated. The output displays only one IP address because there is only one IPv4 address assigned to the system.

The date Command

If we need to find the day of the week, date and time, and time zone, we can use the date command, which is:

date
Output
Fri 30 Jul 2021 02:55:41 AM EET

We can also display the date command to display a specific date using a string format. We need to provide the date in the string format, which means that it must be in quotes. For example, we can display 23th July 1969 with the following command:

date --date="07/23/1969"

There are two things that we must remember when displaying a specific date:

  • When we display the date, it does not impact the system time.
  • The input that we provide must be in the mm/dd/yyyy format. For example, it should be 07/30/2021.
Output
Sun 23 Jul 1961 12:00:00 AM EET

We can also see what day it was some time ago. For example we can see the date fr0m 10 days ago:

date --date="10 days ago"

The date displayed will be 10 days before the current system date. In my case, the system date displays 30th July 2021, the output will display 20th July 2021.

Output
Tue 20 Jul 2021 03:03:21 AM EEST

Other than this, several other parameters are available with the date command. For the time being, we will focus on only a few parameters to get an understanding of how the date command works. We can, however, get the listing of the parameters with the following command:

date --help

The w Command

We may sometimes also need to check who is logged on to our system.

We can use the w command for the same purpose. Besides showing the logged-in users, it also provides time since the system has been up and running. To get this information, execute the following command:

w
Output
 04:27:01 up 2:16, 1 user, load average: 0.18, 0.05, 0.01
USER TTY FROM [email protected] IDLE JCPU PCPU WHAT
edxd :0 :0 02:11 ?xdm? 1:48 0.01s /us

We can also see the information about a specific user. For example, we can view the login details of the user named edxd with the following command:

w edxd

The output displays only the edxd user details.

Output
 04:27:26 up  2:16,  1 user,  load average: 0.12, 0.04, 0.01
USER     TTY      FROM             [email protected]   IDLE   JCPU   PCPU WHAT

The whoami Command

The whoami command displays the name of the currently logged-in user. When we run this command in the terminal, we get the current username as the output. The whoami command is simple:

whoami

When we run this command, the current username is displayed.

Output
edxd

The whoami command generates the same output as another command, which is:

id -un
Output
edxd

 

The whoami command help contains only two parameters, which are:

  • --help
  • --version

There is no other parameter associated with the whoami command.

Conclusion

This article discussed various commands that can help us find more details about our Linux system. We discussed commands, such as w, whoami, uname, uptime, and hostname. These commands are useful when we want to different aspects of a Linux system.

5 Shares:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
You May Also Like
Linux Runlevels Explained
Read More

Linux Runlevels Explained

There are times when Linux system boots either into a Graphical User Interface (GUI) or a command line.…