IntroductionEvery Linux SysAdmin needs to monitor and manage users, hopefully with ease. This is where the Linux
wcommand can help.The
wcommand 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
wcommand 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 SyntaxThe Linux
wcommand 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.
wcommand 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.
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.
LOGIN@: 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_FROMLENenvironment variables, respectively. To learn more, have a look at our guide on setting environment variables in Linux.
wcommand 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 ExamplesCombining options with the
wcommand results in different outputs. Here are some of the things you can do with this command:
Display the Short FormatThe short output format only displays the
WHATfields. To display the short format, use the
wcommand with the
List the w Command Output Without Printing the HeaderIf you want to focus on user information, the
wcommand lets you display the output without the header containing system details and field labels. Use the
-hoption to do this:
Ignore UsernameUsing the
-uoption allows the
wcommand to ignore usernames when calculating the current process and CPU times:
Note: Several users need to be logged in to apply the ignore username
Check the Version of w CommandCheck the current version of the
Display the IP Address in w Command OutputBy default, the
FROMfield 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 StyleDisplaying the output in the old style leaves a blank space under the
PCPUfields for users that have been idle for less than one minute. Use the
-ooption to switch the output to the old style:
Toggle FROM FieldSome Linux distributions, such as Arch Linux, display the
wcommand output without the
FROMfield by default. Others, like Ubuntu, include the
FROMfield in the default output.The
-foption shows or hides the
FROMfield, depending on the system's default output. For example, to hide the
FROMfield in Ubuntu, use:
Display User OutputIncluding a username as an argument with the
wcommand 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 OptionsUsing the
--helpoption displays all the options available for use with the
Note: For a more comprehensive overview of the
wcommand options, use the
man wcommand. Learn more in our guide to the man command.