Every Linux SysAdmin needs to monitor and manage users, hopefully with ease. This is where the Linux
w command can help.
w command is a built-in tool that allows administrators to view information about users that are currently logged in. This includes their username, where they are logged in from, and what they are currently doing.
In this tutorial, we will go over the
w command syntax, break down the details of its output, and give you examples of how you can use it.
- A system running a Linux distribution
- An account with sudo privileges
- Access to the terminal window or command line
w Command in Linux Syntax
w command is a system utility that displays information about currently logged-in users. It uses the following syntax:
w [options] [username]
[options]: Options that change the way the command behaves.
[username]: Entering the name of a specific user only shows information about that particular user in the output.
w command without any additional options produces an output similar to this:
The first line of the output shows system information:
- System time: The current system time.
- Up time: How long the system has logged in.
- Number of users: The number of users currently logged in.
- Average system load: The average number of jobs running on the system in the last 1, 5, and 15 minutes, respectively.
The second line shows user and process information:
USER: The names of currently logged in users.
TTY: The name of the terminal the user is logging in from.
FROM: The name or IP address of the terminal or host the user is logging in from.
[email protected]: The time the user logged in, in a 24-hour format.
IDLE: The time since the user last used the terminal; displays ?xdm? if the user is currently active.
JCPU: The total run time of all system processes attached to the user's terminal.
PCPU: Elapsed time for the user's current process.
WHAT: The name of the user's current process.
Note: You can change the length of the
USER (default of 8 characters) and
FROM (default 16 characters) fields by setting the
PROCPS_FROMLEN environment variables, respectively. To learn more, have a look at our guide on setting environment variables in Linux.
w command uses the following options:
|Print output without the header.|
|Ignores username when calculating current process times and load.|
|Print output in the short format.|
|Toggle printing the FROM (remote hostname) field.|
|Display help text.|
|Replace the hostname in the FROM field with the IP address.|
|Display current command version.|
|Print old-style output (blank space for idle times shorter than 1 minute).|
Note: You can also find information about users and processes in system files. Information on currently logged in users is stored in /var/run/utmp, while /proc contains process information.
w Command in Linux Examples
Combining options with the
w command results in different outputs. Here are some of the things you can do with this command:
Display the Short Format
The short output format only displays the
WHAT fields. To display the short format, use the
w command with the
List the w Command Output Without Printing the Header
If you want to focus on user information, the
w command lets you display the output without the header containing system details and field labels. Use the
-h option to do this:
-u option allows the
w command to ignore usernames when calculating the current process and CPU times:
Note: Several users need to be logged in to apply the ignore username
w command option.
Check the Version of w Command
Check the current version of the
w command with:
Display the IP Address in w Command Output
By default, the
FROM field displays the name of the terminal or remote host the user is logged in from. Switch over to displaying their IP address with the
Output Displayed in Old Style
Displaying the output in the old style leaves a blank space under the
PCPU fields for users that have been idle for less than one minute. Use the
-o option to switch the output to the old style:
Toggle FROM Field
Some Linux distributions, such as Arch Linux, display the
w command output without the
FROM field by default. Others, like Ubuntu, include the
FROM field in the default output.
-f option shows or hides the
FROM field, depending on the system's default output. For example, to hide the
FROM field in Ubuntu, use:
Display User Output
Including a username as an argument with the
w command displays the information for that specific user. For instance, if we want the output to show the information for the user phoenixnap:
Check for Other w Command Options
--help option displays all the options available for use with the
Note: For a more comprehensive overview of the
w command options, use the
man w command. Learn more in our guide to the man command.
After reading this tutorial, you should have a better understanding of the w command, its syntax, and how you can use options to change its output.
For a more comprehensive overview of Linux commands, check out our Linux command cheat sheet.