w – Display the Information of the User Currently Logged into the System

The w command is a Linux command that displays a list of the currently logged-in users on the system. It also provides information about their activity, including the time they logged in, how long they have been idle, and what commands they are currently running.

Overview

To use the w command, simply open a terminal and type w followed by the Enter key. The output will display a list of users currently logged in, including their username, terminal, remote hostname or IP address, login time, idle time, JCPU (total CPU time used by all processes attached to the tty), PCPU (CPU time used by the current process), and the command they are currently running.

$ w
 14:00:00 up 1 day,  5:00,  1 user,  load average: 0.00, 0.01, 0.05
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
johndoe  pts/0    192.168.1.1      12:00    1.00s  0.05s  0.02s w

The output shows that there is only one user logged in (johndoe), and they are logged in from IP address 192.168.1.1 on terminal pts/0. They have been idle for 1 second, and the w command they are currently running has used 0.02 seconds of CPU time.

Specific Use Cases

The w command can be useful in several situations, including:

  • Checking who is currently logged in to a system
  • Determining how long users have been idle
  • Seeing what commands users are currently running
  • Checking if there are any unauthorized users logged in to the system

Options

The w command has several options that can be used to modify its behavior. The available options are:

Option Description
-h Display a help message and exit
-s Display only a summary of the current user’s activity
-f Display full-format listing
-i Ignore idle time and only display active users
-u Display information about the specified user only

Troubleshooting Tips

If the w command is not displaying any output, it is likely that there are no users currently logged in to the system. If you are logged in as a non-root user, you may not have permission to view information about other users. In this case, try running the command as the root user or using the sudo command.

Notes

  • The w command is similar to the who command, but provides more detailed information about the users currently logged in.
  • The w command can be used to determine if there are any unauthorized users logged in to the system, which can be a security risk.