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).
|Root or Sudo Privileges||No|
|Host System and Architecture||Ubuntu 22.10 (x64)|
|OS Compatibility||Ubuntu, Manjaro, Fedora, etc.|
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.
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: The user’s current process with options and arguments.
The following is an example of this command when executed without any options:
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
-h” flag will display the output without showing the header.
$ w -h
Toggle the FROM field
-f” flag will toggle the visibility of the “
FROM” field in the output.
FROM” field; however, Ubuntu includes this field in the output that can be hidden using this flag.
$ w -f
Display the Output in the Old Style
-o” flag will display the output in old style, in which the “
JCPU“, and “
PCPU” fields will be replaced with blank space for the users that have been idle for less than one minute.
$ w -o
Display the Output in a Short Style
-s” flag will display the output in short style, in which the “
JCPU“, and “
PCPU” fields will not be printed.
$ w -s
Display the IP address in the Output
-i” flag will show the IP address instead of the terminal name or remote host in the “
$ w -i
Ignoring the Username
-u” flag will return the output without a username for the current process.
$ w -u
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!