Showing posts with label who. Show all posts
Showing posts with label who. Show all posts

Tuesday, October 4, 2016

who command examples in linux ?

You need to use who command to display users who are currently logged in your server

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'

who command examples
To show a list of all the users currently logged in to the system, type:
$ who
root@linuxforfreshers.com:~$ who
root     :0           2016-10-03 07:46 (:0)
root     pts/61       2016-10-04 08:08 (:0)
root     pts/46       2016-10-04 07:58 (:0)

To show only hostname and user associated with stdin (usually keyboard), enter:
$ who -m
root@linuxforfreshers.com:~$ who -m
root     pts/61       2016-10-04 08:08 (:0)

To show active processes spawned by init:
$ who -p

To show user’s message status as +, – or ?, enter:
$ who -T

root@linuxforfreshers.com:~$ who -T
root     ? :0           2016-10-03 07:46 (:0)
root     + pts/61       2016-10-04 08:08 (:0)
root     + pts/46       2016-10-04 07:58 (:0)

Show or list users logged in
Type the command:
$ who -u
root@linuxforfreshers.com:~$ who -u
root     :0           2016-10-03 07:46   ?          3431 (:0)
root     pts/61       2016-10-04 08:08   .         21700 (:0)
root     pts/46       2016-10-04 07:58 01:46       21700 (:0)

Show time of last system boot
To display time of last system boot pass the -b option to who command:
$ who -b
root@linuxforfreshers.com:~$ who -b
         system boot  2016-10-03 07:44

Show dead processes on the system
You need pass the -d option to who command:
$ who -d
OR
$ who -d -H
root@linuxforfreshers.com:~$ who -d
         pts/9        2016-10-03 16:56                 0 id=/9    term=0 exit=0
         pts/58       2016-10-03 16:56                 0 id=/58   term=0 exit=0
         pts/0        2016-10-03 16:56                 0 id=/0    term=0 exit=0
         pts/60       2016-10-04 15:55                 0 id=/60   term=0 exit=0
         pts/62       2016-10-04 15:55                 0 id=/62   term=0 exit=0

Show system login processes
To just display system login processes pass the -l option:
$ who -l
OR
$ who -l -H
root@linuxforfreshers.com:~$ who -l
LOGIN    tty4         2016-10-03 07:44              1675 id=4
LOGIN    tty5         2016-10-03 07:44              1679 id=5
LOGIN    tty2         2016-10-03 07:44              1687 id=2
LOGIN    tty3         2016-10-03 07:44              1688 id=3
LOGIN    tty6         2016-10-03 07:44              1691 id=6
LOGIN    tty1         2016-10-03 07:44              3142 id=1

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
root@linuxforfreshers.com:~$  who -q
root root root
# users=3

Display the current runlevel
To display the current system runlevel, type:
$ who -r
root@linuxforfreshers.com:~$ who -r
         run-level 2  2016-10-03 07:44

You can combine -r and -b options as follows:
$ who -r -b
root@linuxforfreshers.com:~$ who -r -b
         system boot  2016-10-03 07:44
         run-level 2  2016-10-03 07:44
root@linuxforfreshers.com:~$ who am i
root     pts/61       2016-10-04 08:08 (:0)

Displays "all" information, and headers above each column of data, for example:

root@linuxforfreshers.com:~$ who -aH
NAME       LINE         TIME             IDLE          PID COMMENT  EXIT
           system boot  2016-10-03 07:44
           run-level 2  2016-10-03 07:44
LOGIN      tty4         2016-10-03 07:44              1675 id=4
LOGIN      tty5         2016-10-03 07:44              1679 id=5
LOGIN      tty2         2016-10-03 07:44              1687 id=2
LOGIN      tty3         2016-10-03 07:44              1688 id=3
LOGIN      tty6         2016-10-03 07:44              1691 id=6
LOGIN      tty1         2016-10-03 07:44              3142 id=1
root     ? :0           2016-10-03 07:46   ?          3431 (:0)
           pts/9        2016-10-03 16:56                 0 id=/9    term=0 exit=0
           pts/58       2016-10-03 16:56                 0 id=/58   term=0 exit=0
root     + pts/61       2016-10-04 08:08   .         21700 (:0)
           pts/0        2016-10-03 16:56                 0 id=/0    term=0 exit=0
root     + pts/46       2016-10-04 07:58 01:39       21700 (:0)
           pts/60       2016-10-04 15:55                 0 id=/60   term=0 exit=0
           pts/62       2016-10-04 15:55                 0 id=/62   term=0 exit=0