CLI command "w" on Linux/Unix

w is a very helpful command-line tool for a quick overview of which users are currently logged in and what they are doing.

CLI command "w" on Linux/Unix
Photo by Gabriel Heinzer / Unsplash

Even with years of experience in IT you keep running into something new. Recently I came across the CLI command w.

w gives a quick overview of which users are currently logged in to the system and what they are doing. On systems administered by multiple people, this is a fast way to find out who has an open SSH session and what they are currently up to. Useful during day-to-day work, and especially helpful when troubleshooting: it quickly tells you whether someone has already picked up the issue, or whether there were active SSH sessions at the time the problem occurred.

On a system with only one active SSH session the output looks like this:

 20:58:35 up 49 days,  3:55,  1 user,  load average: 0.01, 0.04, 0.00
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
tobi     pts/0    90.186.XXX.XXX    20:58    1.00s  0.04s  0.00s w

Besides some general information (time of day, uptime, number of users and load average — averaged over the last 1, 5 and 15 minutes), an 8-column table is printed:

  1. the user in question
  2. the environment / terminal ID (TTY = "text input/output environment")
  3. the remote IP address of the user
  4. the time of the login
  5. how long the user has been idle
  6. cumulative CPU time of the user
  7. current CPU usage of the user in percent
  8. the process the user is currently running

This already gives a first impression of which users are logged in and what they are doing. Combined with other CLI tools such as htop, nload or iotop you get a quick picture of the current system state.