who
List users currently logged into the system
By CMD Script Team · 3 min read · Last updated
who [OPTIONS] [FILE]Options
| Flag | Description |
|---|---|
-a | Show all available information, equivalent to combining -b -d --login -p -r -t -T -u |
-b | Show the time of the last system boot |
-q | Show only usernames and a count of logged-in users, in a compact format |
-H | Print a header line above the column output |
-r | Show the current runlevel (or target, on systemd systems) |
-u | Add an IDLE column showing how long since each session was last active |
Distribution compatibility
- Ubuntu
- Debian
- Fedora
- Arch
- macOS (BSD who, similar core output)
What it does
who lists everyone currently logged into the system, showing each session's username,
terminal (tty or pts), and login time, with optional columns for the remote host, idle
time, and process ID. It reads from the live utmp file (typically /var/run/utmp),
which is why it only reflects active sessions — not historical ones.
Beginner examples
who— list all currently logged-in users and their terminalswho -b— show the system's last boot timewho -q— show just usernames plus a total count, in a compact formatwho am i— show details for just the current session (note: no dash, two words)
who
Advanced examples
- Show idle time for every session to spot abandoned logins:
who -u - Combine boot time with current sessions for a quick health check:
who -b; who - Count how many distinct users are logged in:
who -q - Show the current runlevel/target alongside logged-in users:
who -ar - Extract just usernames for scripting:
who | awk '{print $1}' | sort -u
who | awk '{print $1}' | sort -u
Common mistakes
- Expecting
whoto show historical logins — it only reflects sessions that are currently active; uselastfor history. - Confusing
who(a single command, no space) withwho am i(two words) — the latter is a special idiom that shows only the invoking session's own line. - Assuming
who's IDLE column (only shown with-u) is included by default — it isn't; plainwhoomits idle time unless explicitly requested. - Treating
who's user list as authentication/security proof — it reflects session records, not a live permissions check.
Tips
- Use
who -qfor a fast headcount of logged-in users on a busy shared server without scanning full session details. who am iis handy inside scripts or prompts that need to identify "this exact session" rather than the general current user.- Combine
whowithlastwhen investigating access —whofor "right now,"lastfor "how did we get here."
Best practices
- Use
who -u(idle time) before terminating what looks like an abandoned session, to confirm it's actually inactive rather than just quiet. - Prefer
woverwhowhen you also need to know what each user is currently doing, not just that they're logged in. - Don't use
who's output as a sole authorization check in scripts — it's informational, not an access-control mechanism.
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
- Quickly checking who else is logged into a shared server before performing maintenance.
- Confirming system boot time (
who -b) as a lightweight alternative touptime -s. - Scripting a headcount of active sessions for capacity or usage monitoring.
- Spotting unexpected or unfamiliar logged-in sessions during a security check.
Common interview questions
- How is
whodifferent fromw?wholists logged-in users, terminals, and login times;wshows the same information plus a system load summary and what command each user is currently running. - How would you find out when the system last booted using
who?who -bprints the last boot time. - How is
whodifferent fromlast?whoshows only users currently logged in right now;lastshows historical login/logout records, including sessions that have already ended.
Frequently Asked Questions
What's the difference between who and w?
who lists logged-in users, their terminals, login times, and (optionally) remote host and idle time. w includes all of that plus a system load/uptime summary line and, per user, the command they're currently running — essentially who with more detail.
How do I see when the system last booted using who?
Run who -b, which prints a single line showing the system boot time, sourced from the same wtmp/utmp data who normally reads for login sessions.
How is who different from last?
who only shows users currently logged in right now; last shows historical login and logout records, including sessions that have already ended, going back through the rotated wtmp log.
Cheat sheet
Download a quick-reference cheat sheet for who.