Linux commands: who
By Flavio
Published · Updated
Tagged: CLI
Learn how the Linux who command lists the users currently logged in to the system, why you appear multiple times, and what the -aH flags add to the output.
The who command displays the users logged in to the system.
Unless you’re using a server multiple people have access to, chances are you will be the only user logged in, multiple times:

Why multiple times? Because each shell opened will count as an access.
Each line has:
- the user name
- the terminal (the “line”), like
ttys004on macOS orpts/0on Linux. On macOS,consoleis your graphical login session - the date and time the session started
- the remote host, in parentheses, when the session comes from another machine (for example over SSH)
On a server, that last column is the useful one: it tells you where each SSH session is coming from.
Show more details with -aH
The -aH flags will tell who to display more information, including the idle time and the process ID of the terminal:

-H adds the column headings. -a turns on most of the other options at once.
In the idle column, a . means the session was active in the last minute, and old means it’s been idle for more than 24 hours. Otherwise you see hours and minutes, like 12:58.
Who am I?
The special who am i command will list the current terminal session details:


who am i is the same as who -m: it only shows the session attached to your current terminal. In fact any two words work. The GNU version’s help says “‘am i’ or ‘mom likes’ are usual”, so who mom likes does the same thing.
Don’t confuse it with whoami (one word). whoami prints just the name of the user you’re running as, while who am i shows the login session of your terminal. The difference shows up with sudo: sudo whoami prints root, because the command runs as root.
Useful options
These work in both the GNU version (Linux) and the BSD version (macOS):
| Option | What it does |
|---|---|
-H | add column headings |
-q | only the names and the number of users logged in |
-b | time of the last system boot |
-u | add idle time and the process ID of each session |
-T | show if each user accepts messages: + yes, - no, ? error |
-m | only the current terminal, same as who am i |
-s | name, line and time only (the default) |
-a | most of the above at once |
For example, to see when the machine was last started:
who -b
system boot Nov 22 14:14
And to count users:
who -q
flavio flavio
# users = 2
Note that the count is sessions, not people. The same user logged in twice counts twice.
The GNU version on Linux has a few more options, like -r to print the current runlevel, and -l to list login processes. Run man who to see what your system supports.
Using who in scripts
To get the list of distinct users, take the first column and remove duplicates with sort -u:
who | awk '{print $1}' | sort -u
The users command gives you the logged in names on one line:
users
Where the data comes from
who reads the system’s login records file. On macOS that’s /var/run/utmpx, on Linux it’s usually /var/run/utmp.
You can pass a different file as an argument. On Linux, /var/log/wtmp keeps the history of past logins:
who /var/log/wtmp
For past logins, the last command is easier to read.
Related commands
wshows the same users plus the system load and what each one is running right now.whoamiprints your current user name.lastlists recent logins and reboots.
The
whocommand works on Linux, macOS, WSL, and anywhere you have a UNIX environment
Want me to talk about your product? You can sponsor this site.
Related posts about cli: