Cyberithub

9 Useful w command in Linux with Examples

Advertisements

In this article, I will take you through 9 useful w command in Linux with Examples. w is a very basic command line tool used in Linux to find out the users current logged in to the system and the operations or tasks he is currently performing. You can find this tool automatically installed in almost all the Linux Based Systems hence there is no need to download it separately.

Here, we are going to look into different examples of w command in Linux.

9 Useful w command in Linux with Examples 1

w command in Linux

Also Read: 12 Most Popular rm command in Linux with examples

1. List w command in Linux output without header

If you want to remove header information from w command output then you need to use -h option as shown below.

[root@localhost ~]# w -h
root pts/0 192.168.0.102 03:07 0.00s 0.05s 0.00s w -h

-h : Don't print the header.

NOTE:

Please note that I am running all the command here from root user. You can use any user with right privileges to run these commands.

2. Ignore User Name

If you want to check ignore the user name while figuring out the current process and cpu times then you need to use -u flag with w command in Linux as shown below.

[root@localhost ~]# w -u
03:21:07 up 14 min, 1 user, load average: 0.00, 0.08, 0.07
USER  TTY      FROM      LOGIN@ IDLE  JCPU   PCPU  WHAT
root pts/0 192.168.0.102 03:07  3.00s 0.05s  0.00s w -u

-u :Ignores the username while figuring out the current process and cpu times.

Below are the output fields from w command in Linux.

USER – User name.
TTY – Terminal type
FROM – The remote host name or IP address.
LOGIN@ – Login time.
IDLE – Ideal time.
JCPU – The JCPU time is the time used by all processes attached to the tty.
PCPU – The PCPU time is the time used by the current process displayed in WHAT field.
WHAT – The command line of USER’s current process.

3. Check w command version

If you want to check w command version then you need to use -V flag with w command in Linux as shown below. As you can see from below output current w command version is 3.3.10.

[root@localhost ~]# w -V
w from procps-ng 3.3.10

-V :Display version information.

4. Display w command output in short format

If you want to check short output display then you can use -s flag as shown below. With this option you will not able to see LOGIN@, JCPU and PCPU in the output.

[root@localhost ~]# w -s
03:21:14 up 14 min, 1 user, load average: 0.00, 0.07, 0.07
USER TTY      FROM        IDLE   WHAT
root pts/0 192.168.0.102  2.00s  w -s

-s : Use the short format. Don't print the login time, JCPU or PCPU times.

5. Display IP Address in w command output

w command has an option to display ip address in FROM field rather than hostname. You can use -i option with w command to display the IP address in FROM field as shown below.

[root@localhost ~]# w -i
03:21:22 up 14 min, 1 user, load average: 0.00, 0.07, 0.07
USER TTY        FROM     LOGIN@ IDLE  JCPU  PCPU  WHAT
root pts/0 192.168.0.102 03:07  2.00s 0.07s 0.01s w -i

-i : Display IP address instead of hostname for from field.

6. Toggle From Field

There is another option -f available with w command which can be used to remove the from field from w command output as shown below. You might notice that there is no FROM field showing in below output.

[root@localhost ~]# w -f
03:21:30 up 14 min, 1 user, load average: 0.16, 0.10, 0.08
USER TTY   LOGIN@ IDLE  JCPU   PCPU WHAT
root pts/0 03:07  2.00s 0.06s 0.00s w -f

-f : Toggle printing the from (remote hostname) field.

7. Display Output in Old Style

If you want to check w command output in Old style then you need to use -o flag as shown below.

[root@localhost ~]# w -o
03:21:38 up 14 min, 1 user, load average: 0.15, 0.10, 0.08
USER TTY        FROM     LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 192.168.0.102 03:07                 w -o

-o :Old style output. Prints blank space for idle times less than one minute.

8. Display User Output 

You also have an option to choose the user for which you want to see all the information. For example, here I am checking all the centos User activity by running w centos command as shown below.

[root@localhost ~]# w centos
03:41:53 up 34 min, 2 users, load average: 0.08, 0.06, 0.05
USER    TTY       FROM     LOGIN@ IDLE  JCPU  PCPU   WHAT
centos pts/1 192.168.0.102 03:41  6.00s 0.02s 0.02s -bash

9. Check Other w command options

You can use also use --help  flag with w command in Linux to check all the other options currently available and can be used with w command as shown below. More on w command in Linux.

[root@localhost ~]# w --help

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).

-h :Display help text and exit.

 

 

Leave a Comment