who command in Linux - GeeksforGeeks

18 Feb, 2021
who command is used to find out the following information :1. Time of last system boot2. Current run level of the system3. List of logged in users and more.
Description : The who command is used to get information about currently logged in user on to system.
Syntax : $who [options] [filename] 
Examples :1. The who command displays the following information for each user currently logged in to the system if no option is provided :
Login name of the usersTerminal line numbersLogin time of the users in to systemRemote host name of the user
Login name of the users
Terminal line numbers
Login time of the users in to system
Remote host name of the user
hduser@mahesh-Inspiron-3543:~$ who
hduser   tty7         2018-03-18 19:08 (:0)
hduser@mahesh-Inspiron-3543:~$ 

2. To display host name and user associated with standard input such as keyboard
hduser@mahesh-Inspiron-3543:~$ who -m -H
NAME     LINE         TIME             COMMENT

3. To show all active processes which are spawned by INIT process
hduser@mahesh-Inspiron-3543:~$ who -p -H
NAME     LINE         TIME                    PID COMMENT

4. To show status of the users message as +, – or ?
hduser@mahesh-Inspiron-3543:~$ who -T -H
NAME       LINE         TIME             COMMENT
hduser   + tty7         2018-03-18 19:08 (:0)

5. To show list of users logged in to system
hduser@mahesh-Inspiron-3543:~$ who -u
hduser   tty7         2018-03-18 19:08 01:16        3357 (:0)

6. To show time of the system when it booted last time
hduser@mahesh-Inspiron-3543:~$ who -b -H
NAME     LINE         TIME                    PID COMMENT
         system boot  2018-03-18 19:07

7. To show details of all dead processes
hduser@mahesh-Inspiron-3543:~$ who -d -H (NO dead process in this case)
NAME     LINE         TIME             IDLE          PID COMMENT  EXIT 
NAME     LINE         TIME             IDLE          PID COMMENT  EXIT

8. To show system login process details
hduser@mahesh-Inspiron-3543:~$ who -l -H
NAME     LINE         TIME             IDLE          PID COMMENT
LOGIN    tty1         2018-03-18 19:07              3073 id=tty1

9. To count number of users logged on to system
hduser@mahesh-Inspiron-3543:~$ who -q -H
hduser
# users=1

10. To display current run level of the system
hduser@mahesh-Inspiron-3543:~$ who -r
         run-level 5  2018-03-18 19:07

11. To display all details of current logged in user
hduser@mahesh-Inspiron-3543:~$ who -a
           system boot  2018-03-18 19:07
LOGIN      tty1         2018-03-18 19:07              3073 id=tty1
           run-level 5  2018-03-18 19:07
hduser   + tty7         2018-03-18 19:08 01:13        3357 (:0)


12. To display system’s username
hduser@mahesh-Inspiron-3543:~$ whoami
hduser

13. To display list of users and their activities
hduser@mahesh-Inspiron-3543:~$ w
 20:39:20 up  1:32,  1 user,  load average: 0.09, 0.06, 0.07
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
hduser   tty7     :0               19:08    1:32m 38.95s  0.19s /sbin/upstart -

14. To display user identification information
hduser@mahesh-Inspiron-3543:~$ id
uid=1001(hduser) gid=1001(hadoop) groups=1001(hadoop), 27(sudo)

Note : For more details, refer linux man page.YouTubeGeeksforGeeks507K subscribersLinux Tutorials | About the user and the terminal | GeeksforGeeksWatch laterShareCopy link11/36InfoShoppingTap to unmuteIf playback doesn't begin shortly, try restarting your device.You're signed outVideos you watch may be added to the TV's watch history and influence TV recommendations. To avoid this, cancel and sign in to YouTube on your computer.CancelConfirmMore videosMore videosSwitch cameraShareInclude playlistAn error occurred while retrieving sharing information. Please try again later.Watch on0:000:000:00 / 2:30•Live•<div class="player-unavailable"><h1 class="message">An error occurred.</h1><div class="submessage"><a href="https://www.youtube.com/watch?v=WnjofnvIIvg" target="_blank">Try watching this video on www.youtube.com</a>, or enable JavaScript if it is disabled in your browser.</div></div>
linux-command
Linux-system-commands
Linux-Unix
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
ZIP command in Linux with examples
TCP Server-Client implementation in C
SORT command in Linux/Unix with examples
tar command in Linux with examples
curl command in Linux with Examples
Conditional Statements | Shell Script
'crontab' in Linux with Examples
diff command in Linux with examples
Tail command in Linux with examples
UDP Server-Client implementation in C