who Command in Linux: Syntax, Options, Examples

January 15, 2025

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.

who Command in Linux: Syntax, Options, Examples

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:

OptionDescription
-aDisplays all available information, combining multiple options.
-bShows the time of the last system boot.
-dDisplays dead processes that are no longer running.
-HPrints column headers for the output for better readability.
-lLists users who are logged in and waiting to log in.
-mDisplays information about the current terminal session.
-pShows active processes spawned by init.
-qDisplays only the logged-in users and their count.
-rDisplays the current system runlevel.
-sShows the default short who command output.
-TIndicates whether each user's terminal is writable or not.
-uDisplays 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
who terminal output in Linux

Achieve the same effect with the -s option:

who -s
who -s Linux terminal output

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
who -H Linux terminal output

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
who -m Linux terminal output

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
who -l terminal output in Linux

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
who -b terminal output in Linux

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
who -q terminal output in Linux

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
who -T terminal output in Linux

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
Linux who -p terminal output

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
Linux who -d terminal output

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
who -r terminal output in Linux

Display Last System Clock Change

The -t option prints the last time the system clock was changed:

who -t
who -t command terminal output in Linux

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
who -u Linux terminal output

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
who -a terminal output in Linux

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.

Was this article helpful?
YesNo
Sara Zivanov
Sara Zivanov is a technical writer at phoenixNAP who is passionate about making high-tech concepts accessible to everyone. Her experience as a content writer and her background in Engineering and Project Management allows her to streamline complex processes and make them user-friendly through her content.
Next you should read
How Does SSH Work?
December 17, 2020

SSH is a network protocol designed to provide a more secure network communication by employing encryption...
Read more
How to Use SSH Port Forwarding
July 5, 2024

This article demonstrates 3 distinct methods used to port forward SSH connections. It examines...
Read more
How to Set Up Passwordless SSH Login
October 3, 2024

Speed up connecting to remote servers by enabling passwordless SSH login via public key authentication...
Read more
Linux Commands Cheat Sheet: With Examples
November 2, 2023

A list of all the important Linux commands in one place. Find the command you need, whenever you...
Read more