Categories: TutorialsUbuntu

w Command Explained with Examples in Linux

Introduction

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.

In this article, I am going to show you the practical uses of w command.

The Syntax of w command

w[option][username]

Here,the terms option and username are explained below:

Sponsored

[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

The following figure shows the use of w command without any option provided:

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

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.

Sponsored
Sam@linuxways :~$ 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.

Sam@linuxways :~$ 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.

Sam@linuxways :~$ 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.

Sam@linuxways :~$ w -f

The Ubuntu linux system shows the FROM output by default.

Here, 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.

Sam@linuxways :~$ 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.

Sam@linuxways :~$ w -i

Conclusion

The above given command and its example is for a better understanding of the w command. Thank you for checking it out!

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications including CCNA RS, SCP, and ACE. As an IT engineer and technical author, he writes for various websites.

Ubuntu Server Admin

Recent Posts

How to Install nvidia-smi on Ubuntu or Debian Linux

In this article, we will see how to install nvidia-smi on Ubuntu or Debian Linux.…

11 hours ago

How to Install clang tool on Ubuntu or Debian Linux

In this article, we will see how to install clang tool on Ubuntu or Debian…

1 day ago

How to resolve Ubuntu 20.04 Container Signature Errors on Raspberry Pi ARM Devices

When working with Docker containers on Raspberry Pi devices, you might encounter frustrating signature verification…

2 days ago

How to fix DNS Resolution Issues with OpenVPN on Ubuntu 18.04

You’ve recently upgraded to Ubuntu 18.04 and found that your OpenVPN connection no longer resolves…

2 days ago

How to Fix Ubuntu 18.04 System Monitor Launch Issues

Have you ever tried to open System Monitor on your Ubuntu 18.04 system only to…

3 days ago

What is System Hardening? Essential Checklists from OS to Applications

System hardening means locking down a system and reducing its attack surface: removing unnecessary software…

3 days ago