[email protected]Office hours: Mon – Fri 9:00AM – 5:00PMLinkedInXFacebook
NexonHost
Netherlands Dedicated ServersAmsterdam · Equinix AM6Germany Dedicated ServersFrankfurt · Equinix FR4Romania Dedicated ServersBucharest · VoxilityAustria Dedicated ServersVienna · Interxion VIEBulgaria Dedicated ServersSofia · TelepointFrance Dedicated ServersParis · Interxion PAR — Marseille · Digital Realty MRS3Ireland Dedicated ServersDublin · Equinix DB2Italy Dedicated ServersMilan · Irideos AvalonPoland Dedicated ServersWarsawSpain Dedicated ServersMadrid · Equinix MD2United States Dedicated ServersAshburn · Equinix DC
All articles
Getting startedAugust 14, 2023

How to use who command.

How To Use Who Command.

In this article, we explain the who command that is bundled in GNU coreutils package.

who is a command-line utility that prints a list of currently logged in users. It can also show the current run level, time of the last system boot, and more.

 

How to Use the who Command

The basic syntax for the who command is as follows:

who [OPTION]... [ FILE | ARG1 ARG2 ]

When invoked without any option or argument, the output looks something like this:

who
root     pts/0        2023-08-14 11:36 (82.79.3.187)

who will output a formatted list of all users that are currently logged on the system.

Each line contains four fields separated by one or more spaces:

  • The name of the logged user.

  • The user’s terminal.

  • The time when the user logged in.

  • The hostname or IP address from where the user is logged in. To force Ips, use the –ips option.

If you want to print the column headings, add the -H (–heading) option:

who -H
NAME     LINE         TIME             COMMENT
root     pts/0        2023-08-14 11:36 (82.79.3.187)

The command pulls information about the system and who is logged in from the /var/run/utmp file. If you want to use another file, pass the file path to the command.

who accepts two non-option arguments. When invoked with two arguments the command prints information only about the terminal associated with the current user. The same output is displayed when the -m option is used.

You can use any two arguments:

who am iwho mom lovewho foo barwho -m

Each of the commands above will print the same information:

root     pts/0        2023-08-14 11:36 (82.79.3.187)

 

who Command Options

who accepts several options that generally are rarely used.

The -b, –boot option tells who to print the time of last system boot:

who -b
         system boot  2023-06-02 14:44

To get a list of all the dead processes use the -d, –dead option:

who -d

The -r, –runlevel option, tells who to show the current runlevel:

who -r
 run-level 3  2023-06-02 14:44

To get only the user names and the number of currently logged in users, use the -q, –count option:

who -q
root
# users=1

The -a, –all option forces who to print all information:

who -a
           system boot  2023-06-02 14:44
           run-level 3  2023-06-02 14:44
LOGIN      tty1         2023-06-02 14:44               894 id=tty1
root     + pts/0        2023-08-14 11:36   .         22836 (82.79.3.187)
           pts/1        2023-07-07 17:18              1101 id=ts/1  term=0 exit=0
           pts/2        2023-08-07 14:03             21178 id=ts/2  term=0 exit=0
           pts/3        2023-07-12 16:41              6800 id=ts/3  term=0 exit=0
           pts/2        2023-08-14 11:08             22504 id=/2    term=0 exit=0
           pts/3        2023-08-14 11:09             22514 id=/3    term=0 exit=0
           pts/4        2023-08-14 11:09             22523 id=/4    term=0 exit=0
           pts/5        2023-08-14 11:09             22532 id=/5    term=0 exit=0
           pts/6        2023-08-14 11:11             22612 id=/6    term=0 exit=0
           pts/7        2023-08-14 11:11             22622 id=/7    term=0 exit=0
           pts/8        2023-08-14 11:11             22632 id=/8    term=0 exit=0
           pts/9        2023-08-14 11:11             22642 id=/9    term=0 exit=0
           pts/10       2023-08-14 11:11             22652 id=/10   term=0 exit=0
           pts/11       2023-08-14 11:14             22682 id=/11   term=0 exit=0
           pts/12       2023-08-14 11:15             22711 id=/12   term=0 exit=0
           pts/13       2023-08-14 11:18             22763 id=/13   term=0 exit=0

 

Conclusion

The who command prints a list of all currently logged in users.

Keep reading
How to Implement Network Segmentation and Resource Isolation in Linux.
February 6, 2024

How to Implement Network Segmentation and Resource Isolation in Linux.

How to Implement Network Segmentation and Resource Isolation in Linux. Securing and managing networks in a Linux environment involves advanced practices like network segmentation and resource isolation. This guide explores these concepts, providing detailed instructions and examples for…

Read article
How to open or close ports in Linux.
February 6, 2024

How to open or close ports in Linux.

How to open or close ports in Linux. Effectively managing ports on your Linux system is crucial for both security and service accessibility. This comprehensive guide will provide a detailed walkthrough on opening and closing ports using the robust tools iptables and ufw. Understanding these…

Read article
How to use ypdomainname command.
January 23, 2024

How to use ypdomainname command.

How to use ypdomainname command. In the realm of Linux networking, the ypdomainname command plays a crucial role in the context of the Network Information Service (NIS). NIS, formerly known as Yellow Pages, is a distributed database service that facilitates the sharing of network configuration and…

Read article
Get in Touch

Together, Let’s Build a Faster, Safer Internet.

Build scalable infrastructure with NexonHost — high-performance dedicated servers, VPS hosting, colocation, and DDoS protection across Europe.

Get Started →Contact Us
[email protected]Office hours: Mon – Fri 9:00AM – 5:00PM