Sunday, 29 January 2012


who  gives information regarding the users logged in the system, terminals, the  client IP addresses,the start and end times of previous logins and  their other  command  details. It s output is different from that of finger  command. “who” can give the  old details of users processes which  finger cannot

Example 1)
To know the details of users currently logged in a machine,  along with the header, use  who  command  with  –Hu.

home/kamlesh$who   -Hu
Name        Line                Time              Activity          PID                Hostname
kamlesh     pts/0       Jan 07 23:07    15:25        5206202             (
yadav         pts/1       Jan 08 07:40     0:22         3735576              (
stella          pts/2       Jan 08 14:47     0:35         5124214              (
jaffer          pts/5       Jan 08 16:17      .               4108396              (

            Identifies the user's login name.
            Identifies the line name as found in the /dev directory. It is actually the terminal number  of   the user.

            Represents the time when the user logged in.
            Represents the hours and minutes since activity last occurred on that user's line. A . (dot) here       indicates line activity within the last minute. If the line has been quiet more than 24 hours or has not been used since  the last system startup, the entry is marked as old.
            Identifies the process ID of the user's login shell.
            Indicates the name of the machine the user is logged in from.

Who command gets the  information from  /etc/utmp file. If you wish it to use another file, specify the  filename  after who.

To get the output  from    /var/adm/wtmp.

home/kamlesh $who  -Hu    /var/adm/wtmp
Name                    Line                      Time                Activity                  PID              Hostname
kamlesh               pts/2                Dec 28 00:26                .                   930160        (indra)
sneha                  pts/2                  Dec 28 01:09                .                  156080        (indra)
krishna                pts/1                  Dec 28 02:33                .                  660214        (
krishna                pts/2                  Dec 28 02:37                .                  942618        (
justin                   pts/2                   Dec 28 02:51               .                 934590        (
varsha                 pts/2                  Dec 28 03:02                 .                  672308        (indra)
jaffer                   pts/2                   Dec 28 04:27               .                  267016        (
steve                  pts/3                    Dec 28 05:33               15:16           610818        (indra)

All such  old sessions are displayed . so to keep a track on people who logged in and out ,the command helps.

Example 3)
To know the details of your  current session , ie the session from which you are running the command , an easier to remember command is used

home/kamlesh $ who am i
kamlesh    pts/1       Jan 08 01:30     (

Example 4)
In multi user work  environments, you may  require to know  whether your colleague is   logged in from a remote machine or  check continuously  whether  he/she has logged in ,
 Here is a script to do that.

while [ 1 ]
if [ $? -eq 0 ]
      while [ 1 ]
      echo "\a Logged in"
      sleep 1
echo "Not logged in yet"
sleep 5

1 comment: