Beginners Guide for W Command in Linux

Linux TLDR
Last Updated:
Reading time: 3 minutes

The w command is a built-in Linux utility that is capable of listing the usernames of all the users that are currently logged-in, locally or remotely.

In the output, you can view the information of all the logged-in users, like their username, where they are logged-in from, when they are logged-in, and their activity.

In this article, you will learn how to use the “w” command, including its options (with practical examples).

Tutorial Details

Descriptionw
Difficulty LevelLow
Root or Sudo PrivilegesNo
OS CompatibilityUbuntu, Manjaro, Fedora, etc.
Prerequisitesw
Internet RequiredNo

Usage of the W Command

The w command takes two arguments: one is the option, and the other is the username. Both arguments are optional.

$ w [OPTION] [USERNAME]

By default, when the username field is empty, it will print all the logged-in user information; otherwise, you can pass the username to filter out the data for a single user.

Now, when you execute this command without any options, you will be presented with an output similar to this.

w command output

The first line of the output shows the same system information as the uptime command.

  • System time: The current system time.
  • Up time: How long the system has been running.
  • Number of users: The number of logged-in users.
  • Average system load: The number of processes that are either currently being executed by the CPU or are waiting for execution in the last 1, 5, and 15 minutes, respectively.

The second line includes the following fields:

  • USER: The name of the logged-in user.
  • TTY: The name of the terminal line used by the logged-in user.
  • FROM: The host name or IP address from where the user logged-in.
  • LOGIN@: The time when the user logged-in, in 24-hour format.
  • IDLE: The time since the user interacted with the terminal.
  • JCPU: The total time for all the processes used by the user terminal.
  • PCPU: The time used by the user’s current process, which is mentioned in the “WHAT” field.
  • WHAT: The user’s current process with options and arguments.

The following is an example of this command when executed without any options:

$ w

Output:

Usage of w command

Note that all the information related to the currently logged-in users is pulled from the “/var/run/utmp” file, while process related information is stored in the “/proc” directory.

Let’s take a look at some examples with the options offered by this command.

W Command Options

The w command accepts several options; when they are specified, you will get different output. So, let’s start with the first option.

Do Not Print the Header

The “-h” flag will display the output without showing the header.

$ w -h

Output:

w command output without a header

Toggle the FROM field

The “-f” flag will toggle the visibility of the “FROM” field in the output.

📝
Systems like Arch Linux or Fedora do not show the “FROM” field; however, Ubuntu includes this field in the output that can be hidden using this flag.
$ w -f

Output:

w command output without the FROM field

Display the Output in the Old Style

The “-o” flag will display the output in old style, in which the “IDLE“, “JCPU“, and “PCPU” fields will be replaced with blank space for the users that have been idle for less than one minute.

$ w -o

Output:

w command output in old style

Display the Output in a Short Style

The “-s” flag will display the output in short style, in which the “LOGIN@“, “JCPU“, and “PCPU” fields will not be printed.

$ w -s

Output:

w command output in short style

Display the IP address in the Output

The “-i” flag will show the IP address instead of the terminal name or remote host in the “FROM” field.

$ w -i

Output:

w command output with IP address in the "FROM" field

Ignoring the Username

The “-u” flag will return the output without a username for the current process.

$ w -u

Output:

w command output without process username

That was the end of the last example.

Two examples, the “--help” flag (used to display the help section) and the “--version” flag (used to display the version information), are not mentioned as they are self explanatory.

So, let’s conclude this article here as there is nothing left to say, although if you have questions or queries related to this topic, feel free to ask them in the comment section.

Till then, peace!

Join The Conversation

Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.