Linux / Unix: who Command Examples To List Users on The Systems

by on January 27, 2013 · 0 comments· LAST UPDATED January 27, 2014

in , ,

who command

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.

This command is useful to find out the following information:

  1. Time of last system boot.
  2. Current run level.
  3. 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:

Fig. 01: Identifying who is logged on your server

Fig. 01: Identifying who is logged on your server


The sample output in this example shows that the user vivek is logged in on pts/0, and has been on since 14:10 on 27 January. To display line of column headings pass the -H option:
$ 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:

Fig.02: Displaying and counting all users logged on

Fig.02: Displaying and counting all users logged on

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

OptionDescription
-aSame as -b -d --login -p -r -t -T -u
-bTime of last system boot
-dPrint dead processes
-HPrint line of column headings
-lPrint system login processes
-mOnly hostname and user associated with stdin
-pPrint active processes spawned by init
-qAll login names and number of users logged on
-rPrint current runlevel
-tPrint last system clock change
-TAdd user's message status as +, - or ?
-uList users logged in

Related media

This tutorial is also available in a quick video format:

See also
CategoryList of Unix and Linux commands
File Managementcat
Network Utilitiesdighostip
Processes Managementbgchrootdisownfgjobskillkillallpwdxtimepidofpstree
Searchingwhereiswhich
User Informationgroupsidlastlastcommlognameuserswwhowhoamilidmembers

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 0 comments… add one now }

Leave a Comment

Tagged as: , ,

Previous Faq:

Next Faq: