×


w Command in Linux - Explained with Examples

w command is used by the system admin to observe the user logged on to the system and the activities carried out by them. It is the tool used to see the username, logged-in information, and the activities carried out by the logged-in users. This w command tool is automatically installed in the Linux system by default. w command is very much similar to who commands, but with a lot of information about the logged-on users.

Here at Ibmi Media, we shall look into the usefulness of the w command.


What is the Syntax of the w command ?

It is given below:

w[option][username]

Here, the terms option and username are explained below:

  • [options]: option you want to use to know about the user or print the output.
  • [username]: providing the name of the user to know the specific information.


You can see the options of w command, using help menu:

$ w --help


Explanation of w command in Linux terminal

The w commands used in the Linux are about to be mentioned below with an example.

Before starting with the example here are some information you should learn before using the w command. Here are the topic explained about the output displayed in the w command:

  • USER: USER shows the information of the logged in user.
  • TTY: TTY shows the terminal used by the logged in user.
  • FROM: FROM shows the IP address of the logged in user.
  • LOGIN@: LOGIN@ shows the time when the user is logged in.
  • IDLE: IDLE shows the last time when the logged in user interacted with the terminal.
  • JCPU: JCPU shows the time taken by the processes with the attachment to the tty.
  • PCPU: PCPU shows the time taken by the current process .
  • WHAT: WHAT shows the user’s current process and the options.


1. w command without the header

To display the output without a header containing system details and field labels, use the -h options:

$ w -h


2. w command to ignore name

When calculating the current process and CPU times, the -u option allows the w command to ignore usernames:

$ w -u


3. w command to display the short format

w command can be used with the -s option to display short output format which only displays the USER, TTY, FROM, IDLE, and WHAT fields:

$ w -s


4. w command to show/hide remote hostname field

Depending upon the system default output the -f shows the FROM output or hides the FROM output.Here in the Ubuntu linux system the FROM is shown so,to hide the output -f is used:

$ w -f
  • The Ubuntu Linux system shows the FROM output by default.
  • The output FROM is hidden using the options -f.


5. w command to print blank space for idle time

The -o prints the blank space for the idle time less than one minute:

$ w -o


6. w command to display host name

The FROM shows the name of the host or the terminal name by default .Using -i option switches over to the IP address of the user if possible:

$ w -i


7. Check for Other w Command Options

Using the --help option displays all the options available for use with the w command:

w --help


[Need help in fixing Linux System issues ? We can help you. ]


Conclusion

This article covers all you need to know about the w command in Linux. In fact, The w command is a built-in tool that allows administrators to view information about users that are currently logged in. This includes their username, where they are logged in from, and what they are currently doing.


w Command in Linux Syntax

The Linux w command is a system utility that displays information about currently logged-in users. It uses the following syntax:

$ w [options] [username]

Where:

  • [options]: Options that change the way the command behaves.
  • [username]: Entering the name of a specific user only shows information about that particular user in the output.


The w command uses the following options:

  • -h, --no-header Print output without the header.
  • -u, --no-current Ignores username when calculating current process times and load.
  • -s, --short Print output in the short format.
  • -f, --from Toggle printing the FROM (remote hostname) field.
  • --help Display help text.
  • -i, --ip-addr Replace the hostname in the FROM field with the IP address.
  • -V, --version Display current command version.
  • -o, --old-style Print old-style output (blank space for idle times shorter than 1 minute).