The who command is one of the first command we use when troubleshooting common Linux related issues to make sure how many users are logged in and what they are doing. In this post we will see on how to use this command to get more information about who logged into your machine at present and what they are doing.

With this command we can get following basic information.
1)How many users logged into a machine
2)From which server they logged in
3)When is the system booted
4)Which run level the system is booted.

User login details command examples

Example 1: Print information about users logged in.

root@linuxnix:~# who
 root tty1 2015-09-17 21:23
 root pts/0 2016-02-07 07:13 (myhost.linuxnix.com)

If we decode above output,
The first column gives the user name.
Second column gives us which terminal user logged in right now.
Third column gives the comment which may contain date, time and IP/Host name from where they logged in from.

Example 2: Print only user names that are logged in and no other information.

root@linuxnix:/home/surendra# who -q
 surendra surendra surendra surendra surendra
 # users=5

Example 3: Print user login details with headers so that we know what each column is.

root@linuxnix:~# who -H
 NAME LINE TIME COMMENT
 root tty1 2015-09-17 21:23
 root pts/0 2016-02-07 07:13 (myhost.linuxnix.com)

Example 4: I want to see from which IP address user logged in instead of FQDN name.

 root@linuxnix:~# who --ips
 root tty1 2015-09-17 21:23
 root pts/0 2016-02-07 07:13 220.244.12.79

Other useful information with who command

Example 5: Check when is the system last time rebooted.

root@linuxnix:/home/surendra# who -b
 system boot 2016-02-07 14:53

Example 6:We can even find which runlevel the system is booted by using this command.

root@linuxnix:/home/surendra# who -r
 run-level 2 2016-02-07 14:53

Example 7: We can mix above examples or just use -a option to print all information.

root@linuxnix:~# who -a
 system boot 2015-08-28 23:11
 run-level 2 2015-08-28 23:11
 LOGIN tty4 2015-08-28 23:11 841 id=4
 LOGIN tty5 2015-08-28 23:11 844 id=5
 LOGIN tty2 2015-08-28 23:11 855 id=2
 LOGIN tty3 2015-08-28 23:11 856 id=3
 LOGIN tty6 2015-08-28 23:11 859 id=6
 root - tty1 2015-09-17 21:23 old 6944
 root - pts/0 2016-02-07 07:13 . 27318 (myhost.linuxnix.com)
 pts/2 2016-02-01 08:04 6781 id=ts/2 term=0 exit=0
 pts/3 2016-02-01 06:38 7184 id=ts/3 term=0 exit=0

Example 8: We can even get how many local TTY’s a system have.

root@linuxnix:~# who -l
 LOGIN tty4 2015-08-28 23:11 841 id=4
 LOGIN tty5 2015-08-28 23:11 844 id=5
 LOGIN tty2 2015-08-28 23:11 855 id=2
 LOGIN tty3 2015-08-28 23:11 856 id=3
 LOGIN tty6 2015-08-28 23:11 859 id=6
The following two tabs change content below.
Mr Surendra Anne is from Vijayawada, Andhra Pradesh, India. He is a Linux/Open source supporter who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. He works as Devops Engineer with Taggle systems, an IOT automatic water metering company, Sydney . You can contact him at surendra (@) linuxnix dot com.