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.
who w
Try it
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.
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
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,
whoprints nothing andwshows only its header; this is normal because nothing wrote a login record. who am iversuswhoami.who am ishows your terminal's login record and prints nothing when there is none (for example undersuwithout a terminal).whoamiprints 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.
lastis the history, reading/var/log/wtmpfor past logins and reboots;lastlogshows each account's most recent login;usersprints just names on one line.- Reboot and uptime.
who -bgives the boot time anduptimethe running time and load, whichwrepeats in its header. - Output formats differ across systems (BSD, macOS, busybox), so use the options when parsing, and prefer
loginctl list-sessionson systemd machines for a more reliable list. - Messaging.
who -Tshows+or-for whether others can write to the terminal withwriteorwall;mesg nblocks them. - Privacy. Anyone can list sessions on most systems; on hardened ones the
/var/run/utmppermissions orhidepidmount restrict it.