As a system administrator, we need to figure out who is active on the system at a specific time point. We must closely monitor our servers. However, we certainly cannot stare at the system 24 hours a day. In linux, we can use the who command to view the Publisher Information.
What is the who command?
The who command can print information about who is currently logged on to the system. The who command only displays the users actually logged on to the system. It does not display the users who switch users through the su command.
How to Use the who command
In most linux distributions, the who command is installed by default. To use this command, you only need to run the command on the console. Run this command without any options to generate default output.
$ who
How to Understand the output:
- The first column displays the user name.
- The second column shows the user connection mode. Tty means that the user is directly connected to the computer, while pts means remote login.
- Columns 3 and 4 show the date and time respectively.
- The fifth column shows the user's logon IP address.
Use the who command with Parameters
The Who command has some parameters used to adjust the output. The following are common examples.
Display the last restart time and date
Use the-B Option
$ who -b
We can see that the system was started on July 22, December 21, 2013.
Displays the current running level of the initialization process
With the-r option, the who command prints the current running level of the initialization process
$ who -r
The output shows that the system starts to run at Level 2 at on April 9, December 21, 2013.
Add a title for each column
Use the-H option to add a title for each column
$ who -H
Only information about the current running Terminal is printed.
You can use the-m option.
$ who -m
Total number of currently logged-on users
If multiple users log on to the system online at the same time, the-q option will help you complete the counting function.
$ who -q
Additional idle time and PID Information
By default, the who command does not print the idle time and PID information. If you want to display this information, use the-u option. Do not forget to use the-H option to make the displayed information easier to read.
$ who -u -H
The idle time includes the time that has elapsed since the last activity. therefore, means that the user leni has not executed the command for 13 minutes. (.) A symbol indicates that the terminal has been active in the last minute. During that period, we called it "current ". PID is the process ID of the User shell program.
Display Logon Process
Use the-l option
$ who -l
The first column only displays the name of the system logon daemon. The above number 967,971 is the process ID.
Show all information
Use the-a option to display all information. For example:
$ who -a
Summary
You will find that the who command is similar to the w command in some aspects. Do not be confused about why linux should implement similar functions. You can use commands that you think are the most suitable for you or applicable to a certain situation. Please refer to the who command manual for more details.
Linux Command-who-view current Login User
A small example of Linux C Programming-implementing the who command (version 2)
Linux who command parameters and usage