Introduction
Linux system administrators often need access to information about currently logged-in users. The GNU package contains the who
command that provides the necessary options.
In this tutorial, you will learn how to use the who
command to display a list of the logged-in users, see boot time information, processes, and more.
Prerequisites
- A system running Linux.
- Access to the terminal.
Linux who Command Syntax
The syntax for the who
command is:
who [options] [filename]
If you do not specify a file and the options, who
looks for the user information in /var/run/utmp. This file is the default location for storing data on user logins in Linux.
Linux who Command Options
Multiple arguments exist that modify the who
command output. The following table presents common who
command options:
Option | Description |
---|---|
-a | Displays all available information, combining multiple options. |
-b | Shows the time of the last system boot. |
-d | Displays dead processes that are no longer running. |
-H | Prints column headers for the output for better readability. |
-l | Lists users who are logged in and waiting to log in. |
-m | Displays information about the current terminal session. |
-p | Shows active processes spawned by init. |
-q | Displays only the logged-in users and their count. |
-r | Displays the current system runlevel. |
-s | Shows the default short who command output. |
-T | Indicates whether each user's terminal is writable or not. |
-u | Displays additional information, such as idle time and the process ID of each user. |
who Command Examples
The who
command in Linux monitors logged-in users and their session details. It allows you to gather practical information like active users, system boot time, and current runlevel for system management and troubleshooting.
The following text presents some who
command practical use-case examples.
Display Account Information
If you use who
without options, it displays a list of the logged-in user names.
who
Achieve the same effect with the -s
option:
who -s
Note: Some large Linux systems have more active users than the terminal can display on one screen. Pipe who
to the more
command by typing who | more
for a tidy page-by-page look.
Print Column Headers
Use the -H
option to display column names above the list of users:
who -H
Display Only Hostname and User Associated with stdin
To display the information about the current user only, use the -m
flag or add any two arguments to the who
command.
who am I
is a popular example, but any two words produce the same result.
who -m
Note: If the command returns no output and you're accessing the system remotely, ensure you log in with SSH using ssh -t username@hostname
.
Show Available Terminals
For a list of available terminals, use the -l
option:
who -l
In this case, the terminal returns no output. This happens if there are no active login processes, such as when users are already logged in. It's common on systems with graphical logins or remote SSH sessions instead of physical terminals.
Display Time of Last System Boot
The who
command shows the last system boot time when used with the -b
option:
who -b
Display All Login Names and Number of Users Logged On
To list the usernames and the number of users currently logged on the system, add the -q
option:
who -q
Add User's Message Status
Show the user's message status with the -T
option to check the permissions for writing messages to your terminal. Alternatively, use -w
or --mesg
to achieve the same result:
who -T
Possible message statuses are:
+
shows the user has permissions to write to the terminal.-
shows the user does not have permissions to write to the terminal.?
means the system is unable to find the terminal device.
Print Active Processes Spawned by Init
Use who
to display a list of active processes spawned by init, the daemon that starts during the boot process.
To achieve this, add the -p
option:
who -p
In the example above, the terminal shows no output, which happens if the system doesn't have processes directly associated with init or if the processes are not in the expected state.
On modern systems using systemd, these processes won't appear in the same way as they would on older systems using the init system.
Print Dead Processes
For a list of dead processes, use the -d
option:
who -d
If there are no dead processes, the who -d
command returns no output.
Display Current Runlevel
For printing the current system runlevel, use who
with -r
:
who -r
Display Last System Clock Change
The -t
option prints the last time the system clock was changed:
who -t
In this case, the command has no output. This means the system doesn't have a traditional runlevel, which is common in systems using systemd.
Show Idle Time
The -u
option shows how long each user has been idle:
who -u
Force who to Print All Information
Use the who
command with the -a
option to print an output containing the info provided by the -b
, -d
, -l
, -p
, -r
, -t
, -T
, and -u
options:
who -a
The -a
flag is convenient when you do not want to use separate options to print different data.
Conclusion
This tutorial explains how to use the who
command and its options to list only the logged-in users on a Linux system. It also elaborates on the practical use of the who
command.
To learn even more, read our tutorial on how to use the Linux history command.