who Command in Linux

who Command in Linux

Linux_who_command.jpg

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

OUTPUT:

who.png

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

  • 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

OUTPUT:

who_help.png

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 i
who mom love
who foo bar
who -m

OUTPUT:

neo      pts/4        2020-12-11 13:10 (:0)

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

OUTPUT:

         system boot  2020-12-11 12:24

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

OUTPUT:

         run-level 5  2020-12-11 12:28

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

$ who -q

OUTPUT:

neo neo neo neo neo neo
# users=6

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

$ who -a

OUTPUT:

           system boot  2020-12-11 12:24
LOGIN      tty1         2020-12-11 12:24              1723 id=tty1
neo      + tty8         2020-12-11 12:24 01:06        2144 (:0)
neo      + pts/0        2020-12-11 12:26 01:04        2691 (:0)
neo      + pts/1        2020-12-11 12:26 01:04        2691 (:0)
neo      + pts/2        2020-12-11 12:26 01:04        2691 (:0)
neo      + pts/3        2020-12-11 12:26 01:04        2691 (:0)
           run-level 5  2020-12-11 12:28
neo      + pts/4        2020-12-11 13:10   .          7852 (:0)
           pts/5        2020-12-11 13:28                 0 id=/5    term=0 exit=0

Conclusion

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

To get additional information about the users who are currently logged in, check the w command.

If you have any questions, please leave a comment below.who