who Command: Tutorial & Examples

Display a list of users which are currently logged in

The who command is a utility in Linux and other Unix-like operating systems that shows information about users who are currently logged in to the system. When you run the who command, it displays a list of users along with their login names, the terminal they are using, and the time they logged in.

Here is an example of the output of the who command:

who

user1   tty1        2022-12-19 09:15
user2   tty2        2022-12-19 09:17
user3   pts/0       2022-12-19 09:19 (192.168.1.100)

In this example, the who command shows that three users, user1, user2, and user3, are currently logged in to the system. The tty and pts fields indicate the terminal that the user is using to access the system. The tty stands for "teletype" and refers to a physical terminal, while pts stands for "pseudo terminal slave" and refers to a terminal emulator, such as xterm or gnome-terminal. The time that each user logged in is also shown.

You can use the -q option with the who command to show a count of the number of users currently logged in, rather than a list of the users themselves.

who -q
# users=3

You can use the -H option to show a list of the fields that who displays, along with their names. This can be helpful if you want to parse the output of the who command in a script.

who -H
NAME     LINE         TIME              IDLE   PID  COMMENT
user1    tty1         2022-12-19 09:15        1234
user2    tty2         2022-12-19 09:17        1235
user3    pts/0        2022-12-19 09:19        1236  (192.168.1.100)

There are several other options that you can use with the who command to customize its output. For example, you can use the -b option to show the time of the last system boot, or the -u option to show the time that each user was last active on the system. You can see a full list of options by running who --help or by consulting the who man page.

The text above is licensed under CC BY-SA 4.0 CC BY SA