x32x01
ADMINISTRATOR
Introduction
Linux system administrators often need access to information about currently logged-in users. The GNU coreutils package features the who command that provides the necessary options.
In this tutorial, you will learn how to use the who command to display a list of the logged-in users, see boot-time information, processes, and more.
Prerequisites
The syntax for the who command is:
If you do not specify a file after the command and the options, who looks for the user information in /var/run/utmp. This file is the default location for storing data on user logins in Linux.
who Command Examples
The sections below list the who command options, along with some examples.
Display Account Information
If you use who without options, it displays a list of the logged-in user names.
Achieve the same effect with the -s (--short) option:
Note: Some large Linux systems have more active users than the terminal can display on one screen. Pipe who to the more command by typing who | more for a tidy page-by-page look.
Print the Column Headers
Use the -H (--heading) option to display column names above the list of users:
Display Only the Hostname and the User Associated with stdin
To display the information about the current user only, use the -m flag or add any two arguments to the who command.
who am I is a popular example, but any two words produce the same result.
Show Available Terminals
For a list of available terminals, use the -l (--login) option:
Display the Time of the Last System Boot
The who command shows the last system boot time when used with the -b (--boot) option:
Display All Login Names and Number of Users Logged On
To list the usernames and the number of users currently logged on the system, add the -q (--count) option:
Add User’s Message Status
Show the user’s message status with the -T option to check the permissions for writing messages to your terminal. Alternatively, use -w or --mesg to achieve the same result:
Possible message statuses are:
Use who to display a list of active processes spawned by init, the daemon that starts during the boot process.
To achieve this, add the -p (--process) option:
Print Dead Processes
For a list of dead processes, use the -d (--dead) option:
If there are dead processes, the terminal prints an output similar to this:
Display Current Runlevel
For printing the current runlevel of the system, use who with -r (--runlevel)
Display Last System Clock Change
The -t (--time) option prints the last time the system clock was changed:
Show Idle Time
The -u option (--users) shows how long each of the users has been idle:
Force who to Print All Information
Use the who command with the -a (--all) option to print an output containing the info provided by the -b, -d, -l, -p, -r, -t, -T, and -u options:
The -a flag is convenient when you do not want to use separate options to print different data.
Conclusion
After following this tutorial, you should know how to use the who command and its options to list only the logged-in users on a Linux system.
Linux system administrators often need access to information about currently logged-in users. The GNU coreutils package features the who command that provides the necessary options.
In this tutorial, you will learn how to use the who command to display a list of the logged-in users, see boot-time information, processes, and more.
- A system running Linux
- Access to the command line
The syntax for the who command is:
Code:
who [options] [filename]
If you do not specify a file after the command and the options, who looks for the user information in /var/run/utmp. This file is the default location for storing data on user logins in Linux.
who Command Examples
The sections below list the who command options, along with some examples.
Display Account Information
If you use who without options, it displays a list of the logged-in user names.
Code:
who
Code:
who -s
Note: Some large Linux systems have more active users than the terminal can display on one screen. Pipe who to the more command by typing who | more for a tidy page-by-page look.
Print the Column Headers
Use the -H (--heading) option to display column names above the list of users:
Code:
who -H
To display the information about the current user only, use the -m flag or add any two arguments to the who command.
who am I is a popular example, but any two words produce the same result.
Code:
who -m
For a list of available terminals, use the -l (--login) option:
Code:
who -l
Display the Time of the Last System Boot
The who command shows the last system boot time when used with the -b (--boot) option:
Code:
who -b
To list the usernames and the number of users currently logged on the system, add the -q (--count) option:
Code:
who -q
Show the user’s message status with the -T option to check the permissions for writing messages to your terminal. Alternatively, use -w or --mesg to achieve the same result:
Code:
who -T
Possible message statuses are:
- + – The user has permissions to write to the terminal.
- - – The user does not have permissions to write to the terminal.
- ? – Unable to find the terminal device.
Use who to display a list of active processes spawned by init, the daemon that starts during the boot process.
To achieve this, add the -p (--process) option:
Code:
who -p
Print Dead Processes
For a list of dead processes, use the -d (--dead) option:
Code:
who -d
If there are dead processes, the terminal prints an output similar to this:
Code:
[email protected]:~$ who -d
pts/3 2021-01-13 20:22 37405 id=ts/3 term=0 exit=0
pts/4 2021-01-17 10:55 67165 id=ts/4 term=0 exit=04
Display Current Runlevel
For printing the current runlevel of the system, use who with -r (--runlevel)
Code:
who -r
The -t (--time) option prints the last time the system clock was changed:
Code:
who -t
Show Idle Time
The -u option (--users) shows how long each of the users has been idle:
Code:
who -u
Use the who command with the -a (--all) option to print an output containing the info provided by the -b, -d, -l, -p, -r, -t, -T, and -u options:
Code:
who -a
Conclusion
After following this tutorial, you should know how to use the who command and its options to list only the logged-in users on a Linux system.