w Command in Linux: Show Logged-In Users and Activity

By 

Updated on

4 min read

w Command

The w command shows who is logged in to a Linux system and what each user is doing. It also displays the current time, system uptime, number of logged-in users, and load averages.

This article explains how to use the w command in Linux to inspect logged-in users and current system activity.

How to Use the w Command

The syntax for the w command is:

txt
w [OPTIONS] [USER]

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

output
 21:41:07 up 12 days, 10:08,  2 users,  load average: 0.28, 0.20, 0.10
USER      TTY      FROM        LOGIN@   IDLE   JCPU   PCPU WHAT
root      pts/0    10.10.0.2   20:59    1.00s  0.02s  0.00s w
linuxize  pts/1    10.10.0.8   21:41    7.00s  0.00s  0.00s bash

The first line provides the same information as the uptime command. It contains the following values:

  • 21:41:07 - The current system time.
  • up 12 days, 10:08 - The length of time the system has been up.
  • 2 users - The number of logged-in users.
  • load average: 0.28, 0.20, 0.10 - The system load averages for the past 1, 5, and 15 minutes. The system load average is a measurement of the number of jobs that are currently running or waiting for disk I/O. It basically tells you how busy your system has been over the given interval.

The second line includes the following fields:

  • USER – The name of the logged user.
  • TTY – The name of the terminal used by the user.
  • FROM – The host name or IP address from where the user is logged in.
  • LOGIN@ – The time when the user logged in.
  • IDLE – The time since the user last interacted with the terminal. Idle time.
  • JCPU – The time used by all processes attached to the tty.
  • PCPU – The time used by the user’s current process. The one displayed in the WHAT field.
  • WHAT – The user’s current process and options/arguments.

The command then lists all currently logged-in users and the information associated with them.

If you pass one or more usernames as arguments to the w command, the output is restricted to those users:

Terminal
w linuxize
output
 22:08:55 up 12 days, 10:35,  2 users,  load average: 0.00, 0.06, 0.12
USER      TTY      FROM        LOGIN@   IDLE   JCPU   PCPU WHAT
linuxize  pts/1    10.10.0.8   21:41    27:55   0.00s  0.00s bash

w gets information about logged-in users from system session data, typically /var/run/utmp on non-systemd hosts.

w Command Options

w accepts several useful options:

The -h, --no-header option tells w not to print the header:

Terminal
w -h

Only the information about the logged in users is printed:

output
root      pts/0    10.10.0.2   20:59    1.00s  0.02s  0.00s w -h
linuxize  pts/1    10.10.0.8   21:41    7.00s  0.00s  0.00s bash

The -f, --from option toggles the FROM field. Whether this field is shown by default depends on the distribution and build options you are using.

Terminal
w -f
output
 22:48:39 up 12 days, 11:15,  2 users,  load average: 0.03, 0.02, 0.00
USER      TTY        LOGIN@   IDLE   JCPU   PCPU WHAT
root      pts/0     20:59    5.00s  0.03s  0.01s bash
linuxize  pts/1     21:41    1.00s  0.02s  0.00s w -f

The -o, --old-style option tells w to use the old-style output. When this option is used, the command prints blank space when IDLE, JCPU, and PCPU times are less than one minute.

Terminal
w -o
output
 22:50:33 up 12 days, 11:17,  2 users,  load average: 0.14, 0.04, 0.01
USER      TTY      FROM        LOGIN@   IDLE   JCPU   PCPU WHAT
root      pts/0    10.10.0.2   20:59    1:59m               bash
linuxize  pts/1    10.10.0.8   21:41                        w -o

The -s, --short option tells w to use the short output format. When this option is used, the LOGIN@, JCPU, and PCPU fields are not printed.

Terminal
w -s
output
 22:51:48 up 12 days, 11:18,  2 users,  load average: 0.04, 0.03, 0.00
USER      TTY      FROM         IDLE WHAT
root      pts/0    10.10.0.2    3:14  bash
linuxize  pts/1    10.10.0.8    2.00s w -s

The -i, --ip-addr option forces w to show the IP address instead of the hostname in the FROM field.

Terminal
w -i

Conclusion

The w command gives you a quick view of who is logged in and what they are doing. For related tools, see who and uptime .

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page