How to Use the who Command in Linux with Examples

February 25, 2021

Introduction

Linux system administrators often need access to information about currently logged-in users. The GNU coreutils package features 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.

How to Use the who Command in Linux

Prerequisites

  • A system running Linux
  • Access to the command line

Linux who Command Syntax

The syntax for the who command is:

who [options] [filename]

If you do not specify a file after the command 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.

who Command Examples

The sections below list the who command options, along with some examples.

Display Account Information

If you use who without options, it displays a list of the logged-in user names.

who
Using who to print a list of logged users

Achieve the same effect with the -s (--short) 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 the Column Headers

Use the -H (--heading) option to display column names above the list of users:

who -H
Displaying column headers in the output of the who command

Display Only the Hostname and the 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
Using the -m option to display only the current user associated with stdin

Show Available Terminals

For a list of available terminals, use the -l (--login) option:

who -l

Display the Time of the Last System Boot

The who command shows the last system boot time when used with the -b (--boot) option:

who -b
Displaying the time of the last system boot using the who -b command

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 (--count) option:

who -q
Checking the logged-in users count with the who -q option

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
Displaying the user's message status with who -T

Possible message statuses are:

  • + – The user has permissions to write to the terminal.
  • - – The user does not have permissions to write to the terminal.
  • ? – 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 (--process) option:

who -p

Print Dead Processes

For a list of dead processes, use the -d (--dead) option:

who -d

If there are dead processes, the terminal prints an output similar to this:

marko@test-server:~$ who -d
         pts/3        2021-01-13 20:22             37405 id=ts/3  term=0 exit=0
         pts/4        2021-01-17 10:55             67165 id=ts/4  term=0 exit=04

Display Current Runlevel

For printing the current runlevel of the system, use who with -r (--runlevel)

who -r
Checking the current runlevel of the system with who -r

Display Last System Clock Change

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

who -t

Show Idle Time

The -u option (--users) shows how long each of the users has been idle:

who -u
Displaying the users' idle time with who -u

Force who to Print All Information

Use the who command with the -a (--all) option to print an output containing the info provided by the -b, -d, -l, -p, -r, -t, -T, and -u options:

who -a
Printing all information with the who -a command

The -a flag is convenient when you do not want to use separate options to print different data.

Note: For an in-depth look at Linux commands, refer to our article Linux Commands All Users Should Know {Ultimate List}.

Conclusion

After following this tutorial, you should know how to use the who command and its options to list only the logged-in users on a Linux system.

Refer to How to List Users in Linux for information on how to list all users.

Was this article helpful?
YesNo
Marko Aleksic
Marko Aleksić is a Technical Writer at phoenixNAP. His innate curiosity regarding all things IT, combined with over a decade long background in writing, teaching and working in IT-related fields, led him to technical writing, where he has an opportunity to employ his skills and make technology less daunting to everyone.
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
May 18, 2020

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

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

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