Overview of the W Command in Linux

04 May 2023 Balmiki Mandal 0 Linux

Using W Command in Linux

The W command in Linux is a simple and effective way to check for user activity within your system. This command is used by system administrators to check who is logged into the system and what they are doing. In this article, we will discuss how to use the W command and its parameters.

What is the W Command?

The W command (pronounced “double-u”) is a command line utility that prints information about the users currently logged into the system. It provides a list of users, their login names, the last used TTYs, the last used host name, and the amount of time they have been idle. It can also be used to view the processes running on the server.

Syntax of W Command

The W command is used with the following syntax:

w [options] [user]

The options available for use with the W command are listed below.

  • -h — display help message
  • -V — display version information
  • -u — print user information only
  • -s — print system information only
  • -f — print full listing
  • -i — print running and stopped jobs

How to Use the W Command

Now that you know the syntax of the W command, let's take a look at some examples on how to use it. The most basic use of the W command is to simply enter it without any options or user argument. This will return a list of all the users currently logged in and their associated information.

$ w
 17:07:41 up 22 days, 21:36, 11 users, load average: 0.08, 0.06, 0.06
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    192.168.1.1       Thu13   5:46   0.00s  0.03s -bash
jbond    pts/1    192.168.1.17      Wed01   3days  0.00s  0.00s w

This command will show you the username, TTY number, host address, Unix time stamp of when the user logged in, amount of idle time and amount of CPU time used. The WHAT field shows which command the user is currently executing.

You can also use the W command to view information on specific users. To view information on a single user, enter the username as an argument with the W command like so:

$ w jbond
17:07:41 up 22 days, 21:36, 11 users, load average: 0.08, 0.06, 0.06
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
jbond    pts/1    192.168.1.17      Wed01   3days  0.00s  0.00s w

In addition to viewing user information, you can also view process information. For example, if you want to view all running processes, use the -i option like so:

$ w -i
17:07:41 up 22 days, 21:36, 11 users, load average: 0.08, 0.06, 0.06
USER     TTY      FROM              LOGIN@   IDLE   JCPU  PCPU WHAT
root     pts/0    192.168.1.1       Thu13   5:46   0.00s  0.03s -bash
jbond    pts/1    192.168.1.17      Wed01   3days  0.00s  0.00s -bash
       1 root      Ss     2018 Thu13      ?       4:11  0.00s  0.08s /sbin/init
       2 root      Ss+    2018 Thu13      ?       0:02  0.00s  0.01s /sbin/syslogd -n
       3 root      Ss+    2018 Tue12      ?       0:02  0.00s  0.00s /usr/sbin/sshd
      11 postgres  S+     2018 Sat10      ?       2:30  0.00s  0.00s postgres: writer process
      12 postgres  S+     2018 Sat10      ?       0:00  0.00s  0.00s postgres: wal writer process
      13 postgres  S+     2018 Sat10      ?      23:45  0.00s  0.00s postgres: autovacuum launcher process
      14 www-data  S      2018 Mon08      ?       0:00  0.00s  0.00s nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf

The above example shows all running processes, including their PID, user, start time, and what command the process is running. This command is useful for system administrators to quickly view all running processes and easily troubleshoot any issues.

In summary, the W command is a versatile and powerful utility that enables system administrators to monitor user activity within their systems with ease. With the various options available, users can customize the output of the command to their needs.

BY: Balmiki Mandal

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.