Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Permissions and Users

Linux who and w commands

Reference for the Linux who and w commands: list logged-in users, terminals, login times, idle time and running commands, plus boot time and runlevel with who options.

who and w both answer "who is logged in to this machine right now?". who is the plain list: one line per session with user, terminal, login time and origin. w goes further: it adds how long each session has been idle, the CPU time used, and the command each user is currently running, and its first line shows the time, uptime, user count and load averages.

Both read the login records kept in /var/run/utmp. Sessions from SSH, the console and terminal emulators appear there, but background services and programs started without a login (cron, systemd services, containers without a login shell) do not.

Terminal
who
w

Try it

Bash Reading the output when nobody is logged in

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Parsing a who listing

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
who [OPTION]... [FILE | ARG1 ARG2]
w [OPTION]... [USER]

who options:

Option Description
-H, --heading Print a header line.
-q, --count Only names and the number of users logged on.
-b, --boot Time of last system boot.
-r, --runlevel Current runlevel.
-a, --all Everything: boot, logins, dead processes and runlevel.
-u, --users Add idle time and process ID.
-m, am i Only the line for your own terminal (who am i has the same effect).
-s, -T, -w Short format (default); show whether a terminal accepts messages.

w options:

Option Description
-h, --no-header Omit the header lines.
-s, --short Omit login time, JCPU and PCPU.
-f, --from Toggle the FROM (remote host) column.
-i, --ip-addr Show IP addresses instead of host names.
USER Show only that user.

w columns: USER, TTY, FROM, LOGIN@, IDLE, JCPU (CPU time of everything on that terminal), PCPU (CPU time of the current process), WHAT (the command).

Returns: 0 on success. An empty list is not an error.

Usage notes

  • No sessions, no output. In a container, a cron job or a service, who prints nothing and w shows only its header; this is normal because nothing wrote a login record.
  • who am i versus whoami. who am i shows your terminal's login record and prints nothing when there is none (for example under su without a terminal). whoami prints your effective user name.
  • The same user can appear many times, once per terminal. Count unique users with who | awk '{print $1}' | sort -u | wc -l.
  • Idle time is how long since the terminal last saw input. A long idle time is a hint that a session was forgotten, not proof the user is away.
  • last is the history, reading /var/log/wtmp for past logins and reboots; lastlog shows each account's most recent login; users prints just names on one line.
  • Reboot and uptime. who -b gives the boot time and uptime the running time and load, which w repeats in its header.
  • Output formats differ across systems (BSD, macOS, busybox), so use the options when parsing, and prefer loginctl list-sessions on systemd machines for a more reliable list.
  • Messaging. who -T shows + or - for whether others can write to the terminal with write or wall; mesg n blocks them.
  • Privacy. Anyone can list sessions on most systems; on hardened ones the /var/run/utmp permissions or hidepid mount restrict it.