This tutorial explains Linux “who” command, options and its usage with examples.
who command can list the names of users currently logged in, their terminal, the time they have been logged in, and the name of the host from which they have logged in.
who [options] [file]
Same as using the options -b -d –login -p -r -t -T -u.
Display the time of the last system boot.
Display dead processes.
Print a line of column headings.
Print system login processes.
Only print information about the user and host associated with standard input (the terminal where the command was issued). This method adheres to the POSIX standard.
Print active processes spawned by init.
Displays all login names, and a count of all logged-on users.
Print the current runlevel.
Print only name, line, and time fields. This is the default.
Print the last time the system clock was changed, if the information is available.
-T, -w, –mesg
Add a character which indicates the state of the terminal line: “+” if the terminal is writable, “-” if it is not, or “?” if a bad line is encountered.
Print the idle time for each user, and the process ID.
1. Demonstration of -H option
$ who -uH Output: NAME LINE TIME IDLE PID COMMENT abcd ttyp3 Mar 10 11:08 . 4578
This sample output was produced at 11 a.m. The “.” indiacates activity within the last minute.
2. Print Current user’s username
$ who am i abcd
3. Display the username, line, and time of all currently logged-in sessions
$ who lucy pts/1 2014-01-17 22:42 (:0.0) psmith pts/2 2014-01-18 09:30 (:0.0) alan pts/3 2013-12-25 08:52 (:0.0) neil pts/4 2014-01-05 15:33 (:0.0) martha pts/0 2013-09-04 22:05 (:0.0)
4. Get the time of last system boot
The is done using the -b option.
$ who -b system boot 2014-03-07 05:32
5. Get information on system login processes
This is done using the -l option.
$ who -l LOGIN tty4 2014-03-07 05:32 1309 id=4 LOGIN tty5 2014-03-07 05:32 1313 id=5 LOGIN tty2 2014-03-07 05:32 1322 id=2 LOGIN tty3 2014-03-07 05:32 1324 id=3 LOGIN tty6 2014-03-07 05:32 1327 id=6 LOGIN tty1 2014-03-07 05:32 1492 id=1
6. Get the current run level
This is done using the -r option.
$ who -r run-level 2 2014-03-07 05:32
7. Get number of users logged-in and their user names
This is done using the -q option.
$ who -q abc def ghi # users=3
8. Get all the information
This is done using the -a option.
$ who -a system boot 2014-03-07 05:32 run-level 2 2014-03-07 05:32 LOGIN tty4 2014-03-07 05:32 1309 id=4 LOGIN tty5 2014-03-07 05:32 1313 id=5 LOGIN tty2 2014-03-07 05:32 1322 id=2 LOGIN tty3 2014-03-07 05:32 1324 id=3 LOGIN tty6 2014-03-07 05:32 1327 id=6 LOGIN tty1 2014-03-07 05:32 1492 id=1 abc + tty7 2014-03-07 05:33 old 1619 (:0) def + pts/0 2014-03-07 06:47 . 2336 (:0.0) ghi + pts/1 2014-03-07 07:58 . 2336 (:0.0)
Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.
- Practice Programming MCQs
- Buy Information Technology Books
- Buy Linux Books
- Apply for Programming Internship
- Apply for Linux Internship