×

Search anything:

who and w commands in Linux

Internship at OpenGenus

Get this book -> Problems on Array: For Interviews and Competitive Programming

In this article we discuss the who and w Linux command whose functions involve displaying information regarding currently logged in users, useful information for Linux system administrators.

Table of contents.

  1. Introduction.
  2. who command.
  3. w command.
  4. Summary.
  5. References.

who

Introduction.

The who command is used by Linux system administrators to display currently logged in users.

The w command can also be used for this same function, it displays additional information as compared to the who command.

who command

The syntax is as follows,

who [OPTIONS] [FILENAME]

If no filename is specified in the command then who will fetch information from the default location where user information is stored - /var/run/utmp file.

Commands.

  • To get started execute the command,
$ who -H

NAME     LINE         TIME        COMMENT
bob    tty7         Oct  16 22:58 (:0)
alice  pts/0        Oct  16 22:59 (:0)
eve    pts/1        Oct  16 23:43 (:0)

The output shows three currently logged in users.

We can also execute who command without any options,

who
  • We can filter out all the details except the login usernames and their count as by using the -q option,
$ who -q
alice bob eve
# users=3
  • To list only hostnames and users associated with I/O devices(stdin) such as the keyboard we use the -m option,
who -m
  • The -a option lists all information pertaining to currently logged in users,
$ who -aH

NAME       LINE         TIME         IDLE          PID COMMENT  EXIT
           system boot  Oct  16 22:57
LOGIN      tty1         Oct  16 22:58               736 id=tty1
           run-level 5  Oct  16 22:58
bob      + tty7         Oct  16 22:58 07:07         956 (:0)
alice    + pts/0        Oct  16 22:59 07:05        1139 (:0)
eve      - pts/1        Oct  16 23:43   .          3532 (:0)
           pts/2        Oct  16 23:43              1419 id=ts/2  term=0 exit=0

We have used the -H option to print column headings.
Instead of -a we can also use -all option.

  • To list all currently used terminals, we use the -l option,
who -l
  • To display the last time the system was booted we use the -b option,
$ who -b
         system boot  Oct  16 22:57
  • The init deamon is responsible for booting up the system, to view processes spawned by it we use the -p option,
$ who -p
  • To display dead processes we use the -d option,
$ who -d
         pts/2        Oct  16 23:43              1419 id=ts/2  term=0 exit=0
  • To print out the current run level of the system write,
who -r
  • To view current user's username, write,
whoami

or

who am i

For other who command options use the --help option.

who --help

Or read the manual,

man who

w command.

The w command is also used to view currently logged in users and their activities on the system.

The syntax is as follows,

w [OPTIONS]

Commonly used options include,

  • -h, to avoid displaying the header in the output.

  • -u, to ignore the current process username.

  • -s, to display output in short format by excluding some columns.

  • Lets execute the w command without any options,

$ w
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT

From the output we can see 8 columns,

  • USER, this is the name of currently active users.
  • TTY, this is the terminal name.
  • FROM, specifies the hostname/ipaddress from where the user logged in from.
  • LOGIN@, this specifies the time of login for the user.
  • IDLE, specifies the last time a user interacted with the terminal.
  • JCPU, specifies the time taken to attach processes with the terminal.
  • PCPU, is the current process time consumed by the user.
  • WHAT, specifies the current process/arguments of a user.

We can also display information specific to a user as follows,

w alice

For command options execute,

w --help

or to print out the manual,

man w

Summary.

Another command is the id command which when executed will display user identification information.

who command displays logged in users and can also be used to display information such as last time the system was booted, current run level,
w command prints information such as user id and user activities on the system.

References.

  1. Execute the command man command where command can be who, w or id for their manuals.
who and w commands in Linux
Share this