The who command in Linux is a useful tool to find information about the currently logged-in user of the system. It also provides information about the name of the terminal and the time when the user logged in. In brief, the who command is mostly used to examine if a user is currently logged in or find out who is using a specific terminal.
A. Description
The who command is a handy tool to know about the users of a system who are currently logged in.
B. Syntax
The who command in Linux takes OPTION and FILE (as an argument). The syntax for the who command is given below
who [OPTION]... [FILE]
C. Options
Different options can be added to the syntax of the who command to modify the command. Here, I have listed some most used options below. Nevertheless, If you do not find your desired option here, you can look for it on the man (manual) page. To go to the man page, type the following command and press ENTER.
man who
Useful Options
- -b/–boot: It displays the time of the last system boot.
- -d/–dead: It prints the dead processes.
- -H/–heading: It prints the line of column headings.
- –help: It displays the help section and exit.
- -l/–login: It prints the system login processes.
- -q/–count: It prints all the login names and the number of users logged on.
- -r/–runlevel: It prints the current run level.
- -s/–short: It prints only name, line, and time by default.
- -t/–time: It prints the last system clock change.
- -T/-w/–mesg: It adds the user’s message status as +, – or ? which means the user is available for a message, busy hence not available for a message, and not defined respectively.
- -u/–users: It prints the list of the users logged in.
- –version: It displays the version information and exits.
Practical Examples of the “who” Command in Linux
The who command in Linux displays information about the users of the system. Some practical example of the who command is given below.
Example 1: Printing the Current Logged in User With the “who” Command in Linux
You can print the name, terminal name, and login time of currently logged-in users of the system in the terminal using the who command. To do so, follow the below procedures.
Steps to Follow >
➊ At first, open the Ubuntu Terminal.
➋ Then, type the following command in the command prompt:
who
➌ Now, press the ENTER button.
Output >
The below image shows that the who command has printed the name, terminal name, and login time of currently logged-in users of the system in the terminal.
Similar Readings
- The “usermod” Command in Linux [14+ Practical Examples]
- The “users” Command in Linux [4 Practical Examples]
Example 2: Displaying the Hostname and User Associated with the Input/Output Devices
You can display the hostname and user associated with the input/output devices like a keyboard with the -m and -H options of the who command. To achieve so, follow the steps given below.
Steps to Follow >
➊ At first, open the Ubuntu Terminal.
➋ Then, copy the following command in the command prompt:
who -m -H
➌ Now, tap the ENTER button.
Output >
The -m and -H options of the who command have displayed the hostname and user associated with the input/output devices like a keyboard as illustrated in the following image.
Example 3: Displaying All Details of the Currently Logged-in Users
You can see all details of the users currently logged in to the system using the -a option with the who command in Linux. To do so, follow the below procedures.
Steps to Follow >
➊ At first, open the Ubuntu Terminal.
➋ Then, type the following command in the command prompt:
who -a
➌ Now, press the ENTER button.
Output >
The -a option with the who command in Linux has printed all details of the users currently logged in to the system in the terminal, as depicted in the below image.
Example 4: Displaying the Status of the User’s Message Using the “who” Command
You can display the status of the user’s message as “+”,“-“, or “?” using the -T and the -H options of the who command. To achieve so, follow the steps given below.
Steps to Follow >
➊ At first, open the Ubuntu Terminal.
➋ Then, copy the following command in the terminal.
who -T -H
➌ Now, press the ENTER button.
Output >
The following image shows that the -T and the -H options of the who command have displayed the status of the user’s message which is “+” in this case.
Example 5: Display the Whole List of Logged-in Users With the “who” Command in Linux
You can display the whole list of the logged-in users using the -u option of the who command. To do so, follow the below procedures.
Steps to Follow >
➊ At first, open the Ubuntu Terminal.
➋ Then, type the following command in the command prompt.
who -u
➌ Now, press the ENTER button.
Output >
The -u option of the who command has displayed the whole list of the logged-in users, as depicted in the below image.
Example 6: Display the Whole List of Dead Processes Using the “who” Command in Linux
You can display the entire list of all dead processes using the -d, and the -H option of the who command. To achieve so, follow the below procedures.
Steps to Follow >
➊ At first, open the Ubuntu Terminal.
➋ Type the following command in the command prompt:
who -d -H
➌ Now, press the ENTER button.
Output >
The following image illustrates that the -d, and the -H option of the who command has displayed the entire list of all dead processes on my terminal.
Conclusion
In this article, I have demonstrated the process of displaying the information of the currently logged-in users using the who command in Linux. Therefore, I hope you’ll be competent enough to explore more things with the help of these practical examples.
Similar Readings
- The “useradd” Command in Linux [12 Practical Examples]
- The “adduser” Command in Linux [12 Practical Examples]
- The “su” Command in Linux [6 Practical Examples]
- The “userdel” Command in Linux [4 Practical Examples]
FUNDAMENTALS A Complete Guide for Beginners