As a Linux user, sometimes it is required to know some basic information like :
- Time of last system boot
- List of users logged-in
- Current run level etc
Though this type of information can be obtained from various files in the Linux system but there is a command line utility 'who' that does exactly the same for you. In this article, we will discuss the capabilities and features provided by the 'who' command.
The basic syntax of the who command is :
who [OPTION]... [ FILE | ARG1 ARG2 ]
Examples of 'who' command
1. Get the information on currently logged in users
This is done by simply running the 'who' command (without any options). Consider the following example:
$ who
himanshu tty7 2012-08-07 05:33 (:0)
himanshu pts/0 2012-08-07 06:47 (:0.0)
himanshu pts/1 2012-08-07 07:58 (:0.0)
2. Get the time of last system boot
The is done using the -b option. Consider the following example:
$ who -b
system boot 2012-08-07 05:32
So we see that the above output gives the exact date and time of last system boot.
3. Get information on system login processes
This is done using the -l option. Consider the following example:
$ who -l
LOGIN tty4 2012-08-07 05:32 1309 id=4
LOGIN tty5 2012-08-07 05:32 1313 id=5
LOGIN tty2 2012-08-07 05:32 1322 id=2
LOGIN tty3 2012-08-07 05:32 1324 id=3
LOGIN tty6 2012-08-07 05:32 1327 id=6
LOGIN tty1 2012-08-07 05:32 1492 id=1
So we see that information related to system login processes was displayed in the output.
4. Get the hostname and user associated with stdin
This is done using the -m option. Consider the following example:
$ who -m
himanshu pts/1 2012-08-07 07:58 (:0.0)
So we see that the relevant information was produced in the output.
5. Get the current run level
This is done using the -r option. Consider the following example:
$ who -r
run-level 2 2012-08-07 05:32
So we see that the information related to current run level (which is 2) was produced in the output.
6. Get the list of user logged in
This is done using the -u option. Consider the following example:
$ who -u
himanshu tty7 2012-08-07 05:33 old 1619 (:0)
himanshu pts/0 2012-08-07 06:47 00:31 2336 (:0.0)
himanshu pts/1 2012-08-07 07:58 . 2336 (:0.0)
So we see that a list of logged-in users was produced in the output.
7. Get number of users logged-in and their user names
This is done using the -q option. Consider the following example:
$ who -q
himanshu himanshu himanshu
# users=3
So we see that information related to number of logged-in users and their user names was produced in the output.
8. Get all the information
This is done using the -a option. Consider the following example:
$ who -a
system boot 2012-08-07 05:32
run-level 2 2012-08-07 05:32
LOGIN tty4 2012-08-07 05:32 1309 id=4
LOGIN tty5 2012-08-07 05:32 1313 id=5
LOGIN tty2 2012-08-07 05:32 1322 id=2
LOGIN tty3 2012-08-07 05:32 1324 id=3
LOGIN tty6 2012-08-07 05:32 1327 id=6
LOGIN tty1 2012-08-07 05:32 1492 id=1
himanshu + tty7 2012-08-07 05:33 old 1619 (:0)
himanshu + pts/0 2012-08-07 06:47 . 2336 (:0.0)
himanshu + pts/1 2012-08-07 07:58 . 2336 (:0.0)
So we see that all the information that 'who' can print is produced in output.
Tags: 
boot
linux
who
runlevel