How to Use Who Command in Linux?

Linux is famous for its command line support with many utilities to fulfill the user’s requirement.

In the Linux system, the system administrator may sometimes require the information of currently logged-in users. For this purpose, the “who” command is the most suitable utility. The “who” command fetches all the relevant information of the currently logged-in users and displays it on the terminal. Considering its importance, this guide will explain the “who” command with practical usage in the Linux system.

The content that supports these guidelines is as follows:

How Does the who Command Work in Linux?

In Linux, the “who” command is used to present the information about the users that are currently logged in. The syntax of the command is as follows:

General Syntax:

who <options>

Different options that work with the “who” command is explained below:

OptionsDescription
who -sIt displays the account information
who -bThe option refers to the last boot time of the system.
who -HIt represents the headers of the column.
who -qIt shows the login name by assigning a number.
who -rIt refers to the run level system.
who -uIt represents how much time each user remains idle.
who -pThis option represents the number of active processes.
who -dIt shows the dead processes.
who -tIt gives information about the last clock change of the system.

For more details on options, the “–help” flag can be used as given below:

$ who -- help

Let’s carry out the practical implementation of the “who” command:

How to Use the who Command in Linux?

In Linux, the “who” command provides the account information, including login username, dead processes, runlevel, ip address, and many more. Let’s carried out some interesting usage:

Example 1: Display Account Information

To display the account information, the “-s” flag is utilized with the “who” command that can be seen below:

$ who -s

The output shows the information of username as “linux_user1” and login time as “23:23”.

The same command can be used with the “-H” flag to get the headers of the columns, like, “NAME”, “LINE”, “TIME” and “COMMENT”:

$ who -H

The output returns the user information with date and time specified in columns.

To display all information, the “who” command is utilized with “-a” for retrieving all the information of the currently logged-in user as seen below:

The output shows the system boot time, run-level time, and login time information.

Example 2: Last System Boot Time

The execution of the “-b” flag with the “who” command displays the system boot time as below:

$ who -b

The output displays the information of the system boot, including date and time.

Example 3: Username and Total Users

To see the usernames and their numbers, the “-q” flag is utilized with the “who” command:

$ who -q

The output confirms that there is only one user who has logged into this system.

Example 4: Check Run Level

In Linux, you can check the run level (define the state of OS after booting) through the “-r” flag as seen below:

$ who -r

The output shows that “run-level 5” that specifies multi-user mode is enabled.

Example 5: Display Idle Time

To visualize the number of users in an idle state (how long the user remained in an idle state), the “-u” flag can be used with the “who” command:

$ who -u

The “00:15” shows that the “linux_user1” has taken 15 seconds in the idle state.

That is all from this guide.

Conclusion

In Linux, the “who” command displays the information of currently active users. This command works with various options such as “-s” for user account information,”-b” for the system boot time, “-H” to display column headers, etc. This post has briefly demonstrated all the usage of the “who” command in Linux with practical implementation.