- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Linux who Command with Examples
Discover the Power of the Linux "who" Command: Get an In-Depth Look with Practical Examples. The Linux "who" command is a crucial tool for displaying information about users currently logged into the system. From login names to terminal names to login times, the "who" command provides essential details about active user sessions. In this article, we delve into the various options and capabilities of the "who" command, using practical examples to showcase its versatility. By mastering the "who" command, Linux users can effortlessly keep track of active sessions on their system.
Here are some examples showing the use of “who” command −
The Linux "who" command provides valuable insights into active user sessions on the system. Its simple syntax displays information such as login names, terminal names, and login times of users currently logged into the system. The "who" command is essential for tracking and monitoring user activity on a Linux system.
Input
$ who
Output
user1 pts/0 2021-12-20 10:01 (192.168.1.1) user2 pts/1 2021-12-20 10:03 (192.168.1.2)
The "who -b" command in Linux provides details on the date and time of the last system reboot. This information can be beneficial for system administrators to monitor the uptime or to assist in troubleshooting. The "-b" option is utilized to display the boot time information specifically. The syntax of the command is arranged in the following manner:
Input
$ who -b
Output
system boot Jan 19 12:21
The "who --lookup" command in Linux is a powerful tool that displays information about the users who are currently logged into the system along with the hostnames and IP addresses of their computers. This option performs a reverse DNS lookup, transforming IP addresses into hostnames, and providing more insight into user login details like username, terminal name, login time, and hostname or IP address of the system being logged in from. The "--lookup" option can be valuable for scenarios where it is necessary to convert IP addresses into hostnames for more efficient identification.
Input
$ who --lookup
Output
login_name tty terminal_name time login_time hostname
The Linux "who -u" command provides a comprehensive view of the active users on the system. With the "-u" option, the idle time for each user is displayed, giving an insight into how long each user has been inactive. This information is useful for monitoring and tracking user activity on the system. The output of the command includes the user's login name, terminal name, time of login, and the process ID of the command shell. By using the "who -u" command, system administrators can keep track of active user sessions and manage the system resources effectively.
Input
$ who -u
Output
user1 tty1 2023-01-20 11:33 (192.168.1.100) user2 pts/0 2023-01-20 11:34 (192.168.1.101) user3 pts/1 2023-01-20 11:35 (192.168.1.102)
The Linux "who -d" command provides a quick and convenient way to determine the current system's run level, including the time of the last change. This command is particularly useful for monitoring the status of system services and ensuring that the appropriate services are running for the current run level. With the "who -d" command, Linux users can easily access information about the state of their system, allowing them to make informed decisions and troubleshoot potential issues.
Input
$ who -u
Output
run-level 5 Jan 20 14:20 last=S
The Linux "who -H" command provides a clear and organized display of information about the currently logged-in users. The "-H" option adds a header line to the output, making it easier to identify the information displayed. The command shows the login name, terminal name, and the time of the users' logins, all clearly labeled in separate columns for better understanding. This option is especially useful when used in scripts for more precise data processing.
Input
$ who -H
Output
NAME LINE TIME IDLE PID COMMENT user1 tty7 14:35 . 123 (:0) user2 pts/0 15:23 12 456 /usr/bin/ssh user3 pts/1 16:00 . 789 /usr/bin/ssh
In the given example, the content describes the following information:
NAME − The identifier used by a user to access the system is referred to as the 'login name'.
LINE − The specific identification of the terminal device, often referred to as the terminal name.
TIME − The moment when the user established their session
IDLE − The duration of inactivity for the user
PID − The unique identifier of the shell being utilized by the user
COMMENT− One can gather extra details about the user's session, including the display number and the initial command utilized to start the session.
The Linux "who -l" command provides a comprehensive view of the system's current status, including information about active user sessions. The long format output, obtained using the "-l" option, displays not only the details of logged-in users but also additional information about the system, such as the length of time it has been running and the number of users currently logged in. This comprehensive information is displayed in a single-line format for easy reading and understanding.
Input
$ who -l
Output
pts/0 Oct 5 19:41 . 4250 (192.168.1.1) pts/1 Oct 6 11:23 . 5491 (192.168.1.2)
The "who -m" Linux command is a convenient tool for quickly identifying the terminal name of the user currently logged into the system. By using the "-m" option, the output of the command will be limited to the terminal name, as opposed to the more extensive information provided by the standard "who" command. This feature makes the "who -m" command a useful and straightforward way to find the terminal name of your current session in Linux.
Input
$ who -m
Output
robbin tty1 2020-10-01 09:00
The Linux "who -q" command is a simple yet effective way to view the number of users currently logged into the system. With the use of the "-q" option, the output is limited to just the count, making it quick and easy to get the information you need. This command can be particularly useful for system administrators who need to monitor the number of active user sessions on a Linux machine. By understanding the usage of the "who -q" command, a Linux user can quickly and easily check the current user count on their system.
Input
$ who -q
Output
3
Conclusion
In conclusion, the Linux "who" command offers a comprehensive solution for monitoring and displaying information about users who are logged into the system. With its versatile features and options, it enables Linux users to track user sessions, record login times, and determine the number of active users. The "who" a command is an indispensable tool that helps users manage and monitor their Linux systems effectively. Understanding its capabilities and the different ways it can be used is a crucial aspect of being a proficient Linux user.