The who command is used to determine the details of users currently logged in to a system. The output of the who command includes the user name, the name of the system from which the user is connected, and the date and time that the user has been connected since.
Syntax
The syntax of the who command is:
$ who [options]
The who command lists all logged-in users, one user shell per line:
$ who smith :0 Sep 6 17:09 barrett pts/1 Sep 6 17:10 jones pts/2 Sep 8 20:58 jones pts/4 Sep 3 05:11
The -u option can be used to see how long users have been idle. A dot indicates that the users were active up to the last minute, old indicates that the users have been inactive for over 24 hours, and anything between 2 minutes and 23 hours 59 minutes shows the length of time they have been idle. The “am i” option displays information only for the user who runs the command.
If you encounter the below error while running the whoami command:
whoami: command not found
you may try installing the coreutils package as shown below as per your choice of distribution.
Distribution | Command |
---|---|
OS X | brew install coreutils |
Debian | apt-get install coreutils |
Ubuntu | apt-get install coreutils |
Alpine | apk add coreutils |
Arch Linux | pacman -S coreutils |
Kali Linux | apt-get install coreutils |
CentOS | yum install coreutils |
Fedora | dnf install coreutils |
Raspbian | apt-get install coreutils |
who Command Examples
1. To see who is logged in:
# who
2. To see all the users logged in:
# who -a
3. To see last time of system boot:
# who -b
4. To see the dead processes:
# who -d
5. To see the column headings:
# who -H
6. To print system login processes:
# who -l
7. To print active processes spawned by init:
# who -p
8. To count the all logins:
# who -q
9. To print the current runlevel:
# who -r
10. To print system last clock change:
# who -t