W command in Linux

W command in Linux
W command in Linux

The "w" command is an excellent tool for troubleshooting issues on a Linux system. By the end of this article, we will learn some of the basic usages of the w command.

The w command is a basic Linux command that shows who is logged into the system and what they are doing. It also reveals what processes are running on the system and their status.

How to use the w command

To use the w command, type "w" at the terminal.
The syntax is as follows:

w [options] user [...]

It will give you a list of all users that are currently logged into the system, as well as their login time, tty, idle time, and what they are running. For example:

w
 05:44:44 up 1 min,  0 users,  load average: 0.52, 0.58, 0.59
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT

As you see from the output above, there is only one user logged into the system, and they have been idle for 1 minute. The "WHAT" column shows what process the user is running. In this case, the user is running the bash shell.

Options for the w command in Linux

You can use the w command with different options to get different information. For example, if you want to find out more about a specific user, you can use the -u option followed by the username.

-u option

w -u j4y
Output:
 06:25:40 up 42 min,  0 users,  load average: 0.52, 0.58, 0.59
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT

It will show you the user's username, terminal type, login time, idle time, and JCPU.

-h option

With many users, you may sometimes find the header being of no use. To remove the header, you can use the -h option:

w -h

-s option

The s option returns the short version of the output information.

w -s

Output:

06:36:22 up 53 min,  0 users,  load average: 0.52, 0.58, 0.59
USER     TTY      FROM              IDLE WHAT

As you can see, the PCPU, JCPU, and LOGIN@ have been omitted.

These are just a few examples of options that are used mostly. To get a list of all the options, Use the command like this.

w --help

Output:

Usage:
 w [options]

Options:
 -h, --no-header     do not print header
 -u, --no-current    ignore current process username
 -s, --short         short format
 -f, --from          show remote hostname field
 -o, --old-style     old style output
 -i, --ip-addr       display IP address instead of hostname (if possible)

     --help     display this help and exit
 -V, --version  output version information and exit

For more details see w(1).

That is all there is to using the w command in Linux. For more information, consult the man pages(man w).

man w

Conclusion

The w command can be helpful in finding out who is using the most resources on a system. It can also find out who has been logged in for a long time or idle for a long time.
The w command can help in troubleshooting issues on a Linux system. This article goes through some of the primary usages of the w command.

Thanks for reading!

If you enjoy our content, please consider buying us a coffee to support our work:

Table of Contents
Great! Next, complete checkout for full access to GeekBits.
Welcome back! You've successfully signed in.
You've successfully subscribed to GeekBits.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info has been updated.
Your billing was not updated.