Unix ‘who’ Command with More Examples

Hi Folks,

If you are a Linux or Unix user, few questions are raising in your mind always like How to find time of last system boot? Or how to find who are all logged-in system? etc. As a Linux or Unix user we should aware of some basic Unix Commands.

In this blog I’m going to explain features of who – Command, for all Unix/Linux Commands visit All UNIX Commands

Command who
Syntax who [OPTION]… [ FILE | ARG1 ARG2 ]
Description Print information about users who are currently logged in.

 

Start with who –help which gives you all possibilities of who Command.

stephen@stephen:~$ who --help
Usage: who [OPTION]... [ FILE | ARG1 ARG2 ]
Print information about users who are currently logged in.

  -a, --all         same as -b -d --login -p -r -t -T -u
  -b, --boot        time of last system boot
  -d, --dead        print dead processes
  -H, --heading     print line of column headings
      --ips         print ips instead of hostnames. with --lookup,
                    canonicalizes based on stored IP, if available,
                    rather than stored hostname
  -l, --login       print system login processes
      --lookup      attempt to canonicalize hostnames via DNS
  -m                only hostname and user associated with stdin
  -p, --process     print active processes spawned by init
  -q, --count       all login names and number of users logged on
  -r, --runlevel    print current runlevel
  -s, --short       print only name, line, and time (default)
  -t, --time        print last system clock change
  -T, -w, --mesg    add user's message status as +, - or ?
  -u, --users       list users logged in
      --message     same as -T
      --writable    same as -T
      --help     display this help and exit
      --version  output version information and exit

If FILE is not specified, use /var/run/utmp.  /var/log/wtmp as FILE is common.
If ARG1 ARG2 given, -m presumed: 'am i' or 'mom likes' are usual.

Report who bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'who invocation'

who command examples:

1. Get currently logged-in Users:

This who command with no options will give logged-in users list as follows.

stephen@stephen:~$ who
stephen  tty7         2013-12-23 10:22 (:0)
stephen  pts/0        2013-12-23 10:54 (:0)
stephen  pts/11       2013-12-23 14:09 (:0)
stephen  pts/12       2013-12-23 15:22 (:0)

2. Get all (who -a) Logged-in and Users information (-a, –all         same as -b -d –login -p -r -t -T -u):

The following all information getting by who -a command option.

stephen@stephen:~$ who -a
           system boot  2013-12-23 10:21
           run-level 2  2013-12-23 10:21
LOGIN      tty4         2013-12-23 10:21               873 id=4
LOGIN      tty5         2013-12-23 10:21               879 id=5
LOGIN      tty2         2013-12-23 10:21               885 id=2
LOGIN      tty3         2013-12-23 10:21               886 id=3
LOGIN      tty6         2013-12-23 10:21               891 id=6
LOGIN      tty1         2013-12-23 10:21              1213 id=1
stephen  + tty7         2013-12-23 10:22  old         2197 (:0)
stephen  + pts/0        2013-12-23 10:54 04:16        4074 (:0)
stephen  + pts/2        2013-12-23 12:43 02:29        4074 (:0)
stephen  + pts/11       2013-12-23 14:09 00:20        4074 (:0)
stephen  + pts/12       2013-12-23 15:13   .          4074 (:0)

3. Get the last system boot time (-b, –boot        time of last system boot):

The following boot time information getting by who -b command option. It will give you exact last system boot date and time.

stephen@stephen:~$ who -b
         system boot  2013-12-23 10:21

4. Get dead processes (-d, –dead        print dead processes):

This who -d command option will give you all dead processes. Right now there are no dead process in my system.

stephen@stephen:~$ who -d

5. Get information with column headings (-H, –heading     print line of column headings):

This who -H command option will give you lines, on top of it there are header lines for each column.

stephen@stephen:~$ who -H
NAME     LINE         TIME             COMMENT
stephen  tty7         2013-12-23 10:22 (:0)
stephen  pts/0        2013-12-23 10:54 (:0)
stephen  pts/2        2013-12-23 12:43 (:0)
stephen  pts/11       2013-12-23 14:09 (:0)
stephen  pts/12       2013-12-23 15:22 (:0)

6. Get system login information (-l, –login       print system login processes):

This who -l command option will give you all system login information as follows.

stephen@stephen:~$ who -l
LOGIN    tty4         2013-12-23 10:21               873 id=4
LOGIN    tty5         2013-12-23 10:21               879 id=5
LOGIN    tty2         2013-12-23 10:21               885 id=2
LOGIN    tty3         2013-12-23 10:21               886 id=3
LOGIN    tty6         2013-12-23 10:21               891 id=6
LOGIN    tty1         2013-12-23 10:21              1213 id=1

 7. Get hostname and user associated with stdin (-m                only hostname and user associated with stdin):

This who -m command option will give you hostname and user associated with stdin as follows.

stephen@stephen:~$ who -m
stephen  pts/11       2013-12-23 14:09 (:0)

 8. Get active processes spawned by init (-p, –process     print active processes spawned by init):

This who -p command option will give you number of active process by init. Right now there is no active process by init in my system

stephen@stephen:~$ who -p

9. Get all login names and number of users logged on (-q, –count       all login names and number of users logged on): 

This who -q command option will give you all login names and number of users logged on as follows

stephen@stephen:~$ who -q
stephen stephen stephen
# users=3

10. Get current run level (-r, –runlevel    print current runlevel):

This who -r command  option will give you current run level as follows

stephen@stephen:~$ who -r
         run-level 2  2013-12-23 10:21

 11. Get currently logged-in user information.(-s, –short       print only name, line, and time (default)):

This who -s command option will give you currently logged-in user information. It is same as who command with no options (1st point).

stephen@stephen:~$ who -s
stephen  tty7         2013-12-23 10:22 (:0)
stephen  pts/0        2013-12-23 10:54 (:0)
stephen  pts/11       2013-12-23 14:09 (:0)

12. View User Status (-T, -w, –mesg    add user’s message status as +, – or ?):

This who -T, -w command options will give you user status as follows.

stephen@stephen:~$ who -T
stephen  + tty7         2013-12-23 10:22 (:0)
stephen  + pts/0        2013-12-23 10:54 (:0)
stephen  + pts/11       2013-12-23 14:09 (:0)

stephen@stephen:~$ who -w
stephen  + tty7         2013-12-23 10:22 (:0)
stephen  + pts/0        2013-12-23 10:54 (:0)
stephen  + pts/11       2013-12-23 14:09 (:0)

13. Get the all logged-in user list (-u, –users       list users logged in):

This who -u command option will give you all logged-in user list as follows.

stephen@stephen:~$ who -u
stephen  tty7         2013-12-23 10:22  old         2197 (:0)
stephen  pts/0        2013-12-23 10:54 06:21        4074 (:0)
stephen  pts/11       2013-12-23 14:09   .          4074 (:0)

Folks, if you try with any invalid options, then it will through message as follows.

stephen@stephen:~$ who -o
who: invalid option -- 'o'
Try 'who --help' for more information.

I believe that it will help you. I may bring new topic in my next post.

Cheers!


Django-Python Web based application developer.

Share This Post

Related Articles

One Response to “Unix ‘who’ Command with More Examples”

Leave a Reply

© 2017 Techy Diary. All rights reserved.
Powered by Charvi Groups