In this article we discuss the who and w Linux command whose functions involve displaying information regarding currently logged in users, useful information for Linux system administrators.
Table of contents.
- who command.
- w command.
The who command is used by Linux system administrators to display currently logged in users.
The w command can also be used for this same function, it displays additional information as compared to the who command.
The syntax is as follows,
who [OPTIONS] [FILENAME]
If no filename is specified in the command then who will fetch information from the default location where user information is stored - /var/run/utmp file.
- To get started execute the command,
$ who -H NAME LINE TIME COMMENT bob tty7 Oct 16 22:58 (:0) alice pts/0 Oct 16 22:59 (:0) eve pts/1 Oct 16 23:43 (:0)
The output shows three currently logged in users.
We can also execute who command without any options,
- We can filter out all the details except the login usernames and their count as by using the -q option,
$ who -q alice bob eve # users=3
- To list only hostnames and users associated with I/O devices(stdin) such as the keyboard we use the -m option,
- The -a option lists all information pertaining to currently logged in users,
$ who -aH NAME LINE TIME IDLE PID COMMENT EXIT system boot Oct 16 22:57 LOGIN tty1 Oct 16 22:58 736 id=tty1 run-level 5 Oct 16 22:58 bob + tty7 Oct 16 22:58 07:07 956 (:0) alice + pts/0 Oct 16 22:59 07:05 1139 (:0) eve - pts/1 Oct 16 23:43 . 3532 (:0) pts/2 Oct 16 23:43 1419 id=ts/2 term=0 exit=0
We have used the -H option to print column headings.
Instead of -a we can also use -all option.
- To list all currently used terminals, we use the -l option,
- To display the last time the system was booted we use the -b option,
$ who -b system boot Oct 16 22:57
- The init deamon is responsible for booting up the system, to view processes spawned by it we use the -p option,
$ who -p
- To display dead processes we use the -d option,
$ who -d pts/2 Oct 16 23:43 1419 id=ts/2 term=0 exit=0
- To print out the current run level of the system write,
- To view current user's username, write,
who am i
For other who command options use the --help option.
Or read the manual,
The w command is also used to view currently logged in users and their activities on the system.
The syntax is as follows,
Commonly used options include,
-h, to avoid displaying the header in the output.
-u, to ignore the current process username.
-s, to display output in short format by excluding some columns.
Lets execute the w command without any options,
$ w USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
From the output we can see 8 columns,
- USER, this is the name of currently active users.
- TTY, this is the terminal name.
- FROM, specifies the hostname/ipaddress from where the user logged in from.
- LOGIN@, this specifies the time of login for the user.
- IDLE, specifies the last time a user interacted with the terminal.
- JCPU, specifies the time taken to attach processes with the terminal.
- PCPU, is the current process time consumed by the user.
- WHAT, specifies the current process/arguments of a user.
We can also display information specific to a user as follows,
For command options execute,
or to print out the manual,
Another command is the id command which when executed will display user identification information.
who command displays logged in users and can also be used to display information such as last time the system was booted, current run level,
w command prints information such as user id and user activities on the system.
- Execute the command man command where command can be who, w or id for their manuals.