w
Show who is logged in and what they are running
By CMD Script Team · 4 min read · Last updated
w [OPTIONS] [USERNAME]Options
| Flag | Description |
|---|---|
-h | Suppress the header line (useful for scripting/parsing) |
-s | Use the short format, omitting login time and JCPU/PCPU columns |
-f | Toggle display of the FROM (remote host) column |
-u | Ignore username lookup checks, avoiding a hang if user/group lookups are slow |
USERNAME | Show information for a single specified user only, e.g. w shivam |
Distribution compatibility
- Ubuntu
- Debian
- Fedora
- Arch
- macOS (BSD w, similar output, slightly different columns)
What it does
w displays a summary of currently logged-in users along with what each one is doing.
The first line mirrors uptime (current time, system uptime, number of users, load
averages), and each subsequent line shows a user's login name, terminal, remote host (if
applicable), login time, idle time, and the command currently running in that session.
Beginner examples
w— show all logged-in users and their current activityw shivam— show sessions for just the usershivamw -h— show the same output without the header linew -s— show a shorter version with fewer columns
w
Advanced examples
- Script-friendly listing of logged-in usernames only:
w -h | awk '{print $1}' | sort -u - Check how idle each session is to spot abandoned logins: review the
IDLEcolumn - Identify where a suspicious session connected from: check the
FROMcolumn for a remote IP/hostname - Combine with
psto inspect a specific user's running process in more detail oncewshows what they're running - Avoid slow output on systems with unreliable DNS/NIS lookups:
w -u
w -h | awk '{print $1, $3, $NF}'
Common mistakes
- Confusing the
WHATcolumn (currently running foreground command) with a full process list for that user — for a complete picture, useps -u <user>. - Assuming a long
IDLEtime means the user isn't really logged in — it just means no input has been typed in that session for a while; the session may still be valid. - Treating
w's load-average header line as unique tow— it's the same datauptimereports, just bundled at the top. - Forgetting
wonly reflects currently logged-in sessions; for historical login data,lastis the right tool instead.
Tips
- Use
w -hwhen piping intoawk/grepin scripts, so the header row doesn't need to be filtered out separately. - Check the
FROMcolumn first when investigating unexpected logins — it often shows the originating IP or hostname of a remote SSH session. - Run
w <username>to narrow output to one user's sessions on a busy multi-user server instead of scanning the full list.
Best practices
- During an incident response, cross-reference
w'sFROMandLOGIN@columns withlastand system auth logs to build a fuller picture of who has (or had) access. - Don't rely on
IDLEtime alone to decide whether to kill a session — verify what the session is actually doing (WHATcolumn, orps) before terminating it. - On shared servers, periodically checking
wis a lightweight habit for noticing unexpected concurrent logins before they become a problem.
Try it yourself
A simulated shell with a sample home directory — experiment freely, nothing leaves your browser. Type help to list supported commands.
Real-world use cases
- Checking who else is logged into a shared server before performing a risky maintenance operation like a reboot.
- Spotting a suspicious or unfamiliar remote login by reviewing the
FROMcolumn. - Quickly seeing what long-running command a teammate is executing on a shared box.
- Getting an at-a-glance system load summary (same header as
uptime) alongside user activity.
Common interview questions
- How does
wdiffer fromwho?wadds a system load/uptime summary and shows what each logged-in user is currently running (plus CPU time);whoonly lists logged-in users, terminals, and login times. - What do the JCPU and PCPU columns represent? JCPU is total CPU time used by all processes attached to that session; PCPU is CPU time used by just the process shown in the WHAT column.
- How would you check if someone is logged in from a suspicious remote address?
Run
wand inspect theFROMcolumn, which shows the remote hostname/IP for each session.
Frequently Asked Questions
What's the difference between w and who?
who shows a simple list of logged-in users, their terminals, and login times. w shows the same login info plus a system-wide uptime/load-average summary line and, per user, what command they're currently running (the WHAT column) and CPU time used.
What do the JCPU and PCPU columns mean?
JCPU is the total CPU time used by all processes attached to that terminal/session, including currently running background jobs. PCPU is the CPU time used specifically by the process listed in the WHAT column, i.e. the current foreground process.
Why would I see the same user logged in multiple times?
A single user can have several concurrent sessions — multiple SSH connections, several terminal tabs, or a screen/tmux session plus a fresh login — and w lists each session as its own row.
Cheat sheet
Download a quick-reference cheat sheet for w.