How to Show Currently logged in users in Linux

How to check how many users are logged in to the Linux system? There are few commands we can use to show currently logged in users in Linux Operating System.

The users command will print the usernames of the current logged in users.

users

One user could be listed more than once, if the user has logged in from more than one location. We can filter the output with the uniq command to get a unique entry for each user.

users | tr ' ' '\n' | uniq

Get the user count with wc command:

users | tr ' ' '\n' | wc -l

Get the unique user count:

users | tr ' ' '\n' | uniq | wc -l

who command

The who command provides detailed information about currently logged in users.

who
root     tty1         2017-07-17 19:21
user     pts/0        2017-07-17 19:23 (192.168.1.105)
root     pts/1        2017-07-17 19:24 (192.168.1.105)

The who command will show the username, tty (terminal used by the user) and logged in Time. Again, if a user have opened multiple terminals, the user will be listed multiple times.

The --count option will print all usernames and user count.

who --count
root user root
# users=3

The w Command

The w command provides even more detailed information about Linux logged in users.

w
The w command shows Linux logged in users

Show a Listing of Last Logged in users

The last command shows the most recent successful logins to the Linux system.

last

Number of result can be defined with -n option. Following example will show five most recent successful logins.

last -n 5
Show a Listing of Last Logged in users in Linux

As shown in the above screenshot three users are still logged in to the system.