Master the Linux ‘who’ Command: A Comprehensive Guide

Peter Hou
3 min readMay 26, 2023

--

This article provides a comprehensive guide to the ‘who’ command in Linux. It covers the history, usage, common parameters, and some lesser-known tricks related to the command. The ‘who’ command is a valuable tool for system administrators, allowing them to monitor user activity on the system. The article also provides examples and common use cases, making it a great resource for beginners looking to enhance their Linux skills.

Instructions

This article provides a comprehensive guide to the Linux ‘who’ command. It covers the history of the command, its usage, how to use it, and some common parameters. It also provides examples, common use cases, and some tricky skills related to the ‘who’ command.

History

The ‘who’ command in Linux has been around since the early days of Unix. It is part of the GNU core utilities package which is installed on all Unix-like operating systems.

When and why to use it

The ‘who’ command is used to get information about the users who are currently logged into the system. It is useful for system administrators to monitor the system’s user activity.

How to use it

The basic usage of the ‘who’ command is quite simple. Just type ‘who’ in the terminal and press enter.

$ who
username pts/0 2023-05-14 10:18 (192.168.1.1)

The commonly used parameters

  • -a This option prints all information.
$ who -a
system boot
2023-05-14 10:18
username pts/0 2023-05-14 10:18 (192.168.1.1)
  • -b This option prints the time of the last system boot.
$ who -b
system boot 2023-05-14 10:18

Other supported parameters

  • -d Prints dead processes
  • -H Prints column headers
  • -q Prints only names and number of users currently logged on
  • -r Prints current runlevel
  • -s Ignores all other than name and time fields
  • -T Prints user's message status as +, - or ?
  • -u Prints current process and idle status

Most common use cases

One of the most common use cases of the ‘who’ command is to quickly check who is logged into the system. This can be particularly useful in a multi-user environment or for system administrators monitoring system usage.

$ who
username pts/0 2023-05-14 10:18 (192.168.1.1)

The tricky skills

A less known usage of the ‘who’ command is to use it with the ‘am i’ option. This will return the username of the current user, which can be useful in scripts.

$ who am i
username pts/0 2023-05-14 10:18 (192.168.1.1)

What needs to be noted

While ‘who’ is a useful command, it’s important to note that it only provides information about users who are logged into the system. It does not provide information about users who have accounts on the system but are not currently logged in.

Conclusion

The ‘who’ command is a simple yet powerful tool in Linux. It provides valuable information about the users logged into the system, which can be particularly useful for system administrators. With its various options, it allows for a good deal of flexibility in how the information is displayed. Understanding how to use the ‘who’ command effectively can be a great addition to your Linux skills.

--

--

Peter Hou
Peter Hou

Written by Peter Hou

I am a Senior Software Engineer and tech lead in a top tech company.

No responses yet