I am a new Linux and Unix system user. How do I display who is logged on my Linux or Unix-like operating system using shell prompt?
You need to use who command to display users who are currently logged in your server.[donotprint]
who command details | |
---|---|
Description | Find who is on the system |
Category | N/A |
Difficulty | Easy |
Root privileges | No |
Estimated completion time | 5m |
- Time of last system boot.
- Current run level.
- List of logged in users and more.
Purpose
Display who is on the system.
Syntax
The basic syntax is as follows:
who
who am i
who [options] [File]
who --help
who --version
who | grep 'userNameHere'
Where,
- If no non-options provided, who displays the following information for each user currently logged on:
- login name
- terminal line
- login time
- remote hostname or X display
- If you give one non-option argument, who uses that instead of a default system-maintained file such s /var/run/utmp as the name of the file containing the record of users logged on.
- If given two non-option arguments, who prints only the entry for the user running it preceded by the hostname. Traditionally, the two arguments given are ‘am i’, as in ‘who am i’.
who command examples
To show a list of all the users currently logged in to the system, type:
$ who
Sample outputs:
$ who -H
To show only hostname and user associated with stdin (usually keyboard), enter:
$ who -m
To show active processes spawned by init:
$ who -p
To show user’s message status as +, – or ?, enter:
$ who -T
Show or list users logged in
Type the command:
$ who -u
Show time of last system boot
To display time of last system boot pass the -b option to who command:
$ who -b
Sample outputs:
system boot 2014-01-05 10:02
The output in this example, shows that the system was booted since 10:02 on 05 January.
Show dead processes on the system
You need pass the -d option to who command:
$ who -d
OR
$ who -d -H
Sample outputs:
NAME LINE TIME IDLE PID COMMENT EXIT pts/1 2014-01-11 09:17 56094 id=ts/1 term=0 exit=0 pts/2 2014-01-05 15:46 11070 id=ts/2 term=0 exit=0 pts/2 2014-01-08 03:31 3614 id=/2 term=0 exit=0 pts/1 2014-01-11 16:54 64559 id=/1 term=0 exit=0 pts/3 2014-01-11 17:13 15818 id=/3 term=0 exit=0 pts/4 2014-01-25 11:02 46807 id=ts/4 term=0 exit=0
Show system login processes
To just display system login processes pass the -l option:
$ who -l
OR
$ who -l -H
Sample outputs:
NAME LINE TIME IDLE PID COMMENT LOGIN tty2 2014-01-05 10:03 8750 id=2 LOGIN tty1 2014-01-05 10:03 8748 id=1 LOGIN tty3 2014-01-05 10:03 8752 id=3 LOGIN /dev/ttyS1 2014-01-05 10:03 8747 id=v/tt LOGIN tty4 2014-01-05 10:03 8754 id=4 LOGIN tty5 2014-01-05 10:03 8756 id=5 LOGIN tty6 2014-01-05 10:03 8758 id=6
Count all login names and number of users logged on the system
To count all login names and number of users logged on:
$ who -q
Sample outputs:
Display the current runlevel
To display the current system runlevel, type:
$ who -r
Sample outputs:
run-level 3 2014-01-05 10:02
You can combine -r and -b options as follows:
$ who -r -b
Sample outputs:
system boot 2014-01-05 10:02 run-level 3 2014-01-05 10:02
Display all
The -a is same as same as -bdprtTu options as discussed earlier:
Sample outputs:
NAME LINE TIME IDLE PID COMMENT EXIT system boot 2014-01-05 10:02 run-level 3 2014-01-05 10:02 LOGIN tty2 2014-01-05 10:03 8750 id=2 LOGIN tty1 2014-01-05 10:03 8748 id=1 LOGIN tty3 2014-01-05 10:03 8752 id=3 LOGIN /dev/ttyS1 2014-01-05 10:03 8747 id=v/tt LOGIN tty4 2014-01-05 10:03 8754 id=4 LOGIN tty5 2014-01-05 10:03 8756 id=5 LOGIN tty6 2014-01-05 10:03 8758 id=6 root + pts/0 2014-01-27 03:37 . 11149 (10.1.6.120) pts/1 2014-01-11 09:17 56094 id=ts/1 term=0 exit=0 pts/2 2014-01-05 15:46 11070 id=ts/2 term=0 exit=0 pts/2 2014-01-08 03:31 3614 id=/2 term=0 exit=0 pts/1 2014-01-11 16:54 64559 id=/1 term=0 exit=0 pts/3 2014-01-11 17:13 15818 id=/3 term=0 exit=0 pts/4 2014-01-25 11:02 46807 id=ts/4 term=0 exit=0
who command options
Option | Description |
-a | Same as -b -d –login -p -r -t -T -u |
-b | Time of last system boot |
-d | Print dead processes |
-H | Print line of column headings |
-l | Print system login processes |
-m | Only hostname and user associated with stdin |
-p | Print active processes spawned by init |
-q | All login names and number of users logged on |
-r | Print current runlevel |
-t | Print last system clock change |
-T | Add user’s message status as +, – or ? |
-u | List users logged in |
Related media
This tutorial is also available in a quick video format:
See also
- /var/run/utmp file.
- /var/log/wtmp file.
- who(1) Linux/Unix command man page
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 1 comment... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
How would check the top logins? For example; if you have to figure out the top 5 logins, what would be the script?