With the help of who command in Linux, you can instruct your system to display the details about users currently logged in to the Unix system together with their associated activities.
When we talk about the who commands in Linux, it stands out as a command-line utility that helps display the list of all the currently logged-in users in any system. Besides printing the general information, the command also shows the current run level, system login process details, time of the last system boot, and many more vital details.
Using the Who Command in Linux
The general $ who
command is used to display various information about the users that are currently logged in to a specific system. The information includes the user’s login name, login time, alongside the terminal line numbers and the remote host.
The usage of who commands in Linux is, however, very versatile. In other words, the command can be used together with various options for displaying user information in different ways.
Here is what you can find using who commands:
- Hostname
- All active processes
- List of logged in users
- Status of user message
- List of dead processes
- Time of last system boot.
- Details of users that are currently logged in.
- Current run level status.
- System login process details.
- User list and activities.
- User identification information.
- System username.
The Command Syntax
When we talk about the basic syntax of who commands, it looks something like this:
who [OPTION]... [ FILE | ARG1 ARG2 ] or who [OPTION]... [FILENAME]
When the command is used without any option or argument, it instructs the system to print a formatted list of users logged in to the system. The command usually derives all the required system and user details from the /var/run/utmp
file.
Various Uses of Who Commands in Linux
Displaying Host Name with Standard Input
In order to display the hostname and also the user associated with all the standard input, use the following command:
$ who -m -H

Displaying All Active Processes
If you’re willing to make your system display all the active processes that are actually spawned by the INIT
process, use the following command:
$ who -p -H

Displaying List of Logged Users
Running the following command will help you access the list of users who are logged in to your system.
$ who -u

Displaying the Status of User Message
To have a look at the status of the user messages and that too in +,-
format, make sure to run the following command:
$ who -T -H

Displaying List of Dead Processes
Sometimes, accessing the list of dead processes in Linux becomes essential. Luckily, who commands can be used to seamlessly make the system display the list in no time.
$ who -d -H

Displaying the Time of Last Boot
Are you wondering when the last time was your system booted? Well, in that case, use the following command and see the information with no effort.
$ who -b -H

Displaying the Details of Users that are Currently Logged In
To get all the information about the user who’s currently logged in to the concerned Linux system, make use of the following command:
$ who -a

Displaying the System’s Current Run Level
Don’t know about the current run level of your system? In that case, running the following command will help you grab the necessary information.
$ who -r

Counting the Number of Logged-In Users
Getting hold of the total number of users who’re logged in to the system is pretty straightforward. Open the Terminal and run the following command:
$ who -q -H

Displaying the System Login Process Details
The who commands are also helpful in collecting information about the system login process details. Here is the command that actually shows the desired data:
$ who -1 -H
Other Uses of Who Command in Linux
Apart from the conventional who commands, there are other related ways to get information about users and their activities in Linux. Following are a few cases that will help you understand the usage of the associated commands.
Displaying the System’s Username
To show the username of the system, use the following command:
$ whoami

Displaying the User List and the Activities
For making your system show the list of users alongside their activities, run the following command:
$ w

Displaying User Identification Information
Besides accessing various other details about the users that are logged in to your system, who commands also help display the user identification information. For that, all you need to do is, launch the Terminal and run the command as:
$ id

And this is pretty much everything about who commands in Linux. In this article, we’ve looked at thirteen varied uses of who command in accessing various information about the users who are logged in to any Unix system.
As soon as you’re done walking through the entire tutorial, you’ll have a fair idea about using who commands in the most promising manner. For any queries, leave a comment below.
If this guide helped you, please share it.