In system administration, one of the basics that you need to be familiar with is user management. On Linux, you will need utilities like the w command, that shows information about users that are currently logged in—along with their activities. It also displays how long the system has been running, the system load average, and the current time.
Upon running the command, you will see the following headers printed out in this order: current time, how long the system’s been running, the number of users currently logged in, and system load averages for the past 1 minute, 5 minutes, and 15 minutes.
The following columns are printed out for each user: user name, the TTY, the remote host, login time (date, month, and year), idle time, JCPU (time used by all processes related to the TTY), PCPU (time used by the current process which shows in the WHAT column), and the command line of their current process.
w
command is installed by default on almost all Linux distros; hence there is no need to download and install it separately. In case your distro does not have the w
command, you may use the who command to display currently logged-in users as an alternative.
Basic Syntax
This is what the basic syntax for the w
command looks like:
$ w [OPTIONS] [USERNAME]
The w Command: Different Options
By combining command-line options with the w
command, you will get different results for your output. Here are the various options you can use with this command:
Command-line Options:
-h
,--no-header
: This will give you an output with no headers.-u
,--no-current
: This will Ignore the username while analyzing the current CPU times and process.-s
,--short
: This will output the short format. Login time, JCPU or PCPU times will not be included in the result.-f
,--from
: This will toggle printing out the ‘from’ or ‘remote hostname’ field.--help
: This will display the help information and then exit.-i
,--ip-addr
: Using this will display the IP address instead of hostname for the ‘from’ field.-V
,--version
: This will display the version information.-o
,--old-style
: This will show the output in Old style and prints out a blank space for idle times that are less than one minute.user
: This will show information for a specified user.
Environment:
PROCPS_USERLEN
: This will override the default width of the username column to ‘8’.PROCPS_FROMLEN
: This will override the default width of the username from column to ‘16’.
Files:
/var/run/utmp
: This is where you find information about who is logged in./proc
: This is where you find process information.
Prerequisite
All you need is a system running a Linux OS with the w
command installed, a sudo privileged user account, and a Terminal.
How to Use the w Command on Linux?
Now that you have all the necessary information let’s pull up a Terminal and find out what we can do with the w command on Linux.
Run w Command Without Any Option or Argument
Syntax:
$ w
By executing the w
command without any options, you will get an output similar to this:
As you can see, simply running the w command on its own will show you a bunch of data you may, or may not need.
First, let’s discuss what all of this information means. In the first line, from left to right, you will see the current System Time “22:03:40”, Up Time “8:19” (8 hours and 19 minutes), Number of Users “3”, and the Average System Load “0.04, 0.10, 0.08”.
In the second line, you will see the following headers: USER, TTY, FROM, LOGIN@, IDLE, JCPU, PCPU, and WHAT. These are the users’ columns, and the information about the processes they are currently running.
Different Headers:
- USER: Users that are currently logged in.
- TTY: Terminal name where the user logged in from.
- FROM: Terminal name or Terminal IP address or host where the user logged in from.
- LOGIN@: Time when the user logged in. This is in the 24-hour format.
- IDLE: Time user last used the Terminal; “?xdm?” means the user is currently active.
- JCPU: Total time of all system processes has been running.
- PCPU: Current elapsed time for the process.
- WHAT: Name of the current process.
Run the w Command Without the Headers
Syntax:
$ w -h
Or
$ w --no-header
Here you can see what happens if you use the option -h
or --no-header
. You can use this option if you need to focus on user information. With this option, you get output without the headers.
Run w Command in Short Format
Syntax:
$ w -s
Or
$ w --short
This is what you get using the -s
or --short
option; you get an output in the short format. The short format does not include the Login, JCPU, and PCPU times.
Run w Command Without the From Field
Syntax:
$ w -f
Or
$ w --from
Some Linux distros, like Arch Linux, do not include the From field by default when running the w
command. Other distros like Ubuntu and CentOS have the From field by default.
The -f
or --from
option depending on what distro your Linux system is, will toggle the From field on and off.
Check Other Options
Syntax:
$ w --help
Using the --help
option will show all the other options available for the w
command.
Check the w command Version
Syntax:
$ w -V
Or
$ w --version
To get the current version of the w
command on your system, the -V
or --version
is the option you will need to use.
As you can see, the current version of the w
command is 3.3.10.
Run the w Command in Old Style
Syntax:
$ w -o
Or
$ w --old-style
The -o
or --old-style
option gives you an output with blank spaces under the fields IDLE, JCPU, and PCPU if a user has been idle for less than one minute.
And that marks the end of this tutorial. We looked at what the w command is all about. We’ve also learned how to use the w command on Linux and get different results as needed.
If this guide helped you, please share it. 🙂