How to use the command 'w' (with examples)

How to use the command 'w' (with examples)

The w command is used to show who is logged on and what they are doing on a system. It provides information about the user login, TTY (terminal), remote host, login time, idle time, and the current process. The command can be useful for system administrators to monitor user activity and identify any potential issues or bottlenecks.

Use case 1: Show logged-in users info

Code:

w

Motivation: The motivation for running this command is to obtain a list of all the currently logged-in users on the system and the tasks they are performing. This can be helpful for system administrators to keep track of the system’s load and resource usage.

Explanation: The w command without any arguments simply displays the information about the logged-in users. It shows the user name, TTY (terminal), remote host (if applicable), login time, idle time, and the current process.

Example output:

13:33:05 up 7 days,  2:17, 12 users,  load average: 0.64, 0.94, 0.99
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
john     tty1                      10:22   14:10   0.88s  0.02s vim
mary     pts/0    192.168.1.10     10:45   1:23    0.10s  0.05s sshd: mary@pts/0
david    pts/1    192.168.1.12     11:01   0.33s   0.19s  0.00s w
jane     pts/2    192.168.1.15     11:25   55:19   0.30s  0.03s bash

Use case 2: Show logged-in users info without a header

Code:

w -h

Motivation: The motivation for using this command is to obtain a simplified output without the header information. If you need a cleaner and more concise overview of the currently logged-in users’ activities, this option can be useful.

Explanation: The -h option is used to remove the header line from the command output. It can be combined with the w command to eliminate the header and display only the information about the logged-in users.

Example output:

john     tty1                      10:22   14:10   0.88s  0.02s vim
mary     pts/0    192.168.1.10     10:45   1:23    0.10s  0.05s sshd: mary@pts/0
david    pts/1    192.168.1.12     11:01   0.33s   0.19s  0.00s w
jane     pts/2    192.168.1.15     11:25   55:19   0.30s  0.03s bash

Conclusion:

In this article, we explored the different use cases of the w command. We saw how it can be used to display the information about the logged-in users, their activities, and system resource usage. By utilizing the w command, system administrators can gain valuable insights into user’s login information and identify potential issues.

Related Posts

Managing Heroku Apps (with examples)

Managing Heroku Apps (with examples)

1. Log in to your Heroku account To log in to your Heroku account, you can use the heroku login command.

Read More
How to use the command 'git checkout-index' (with examples)

How to use the command 'git checkout-index' (with examples)

The ‘git checkout-index’ command is used to copy files from the index to the working tree.

Read More
How to Use the Command ppmfade (with examples)

How to Use the Command ppmfade (with examples)

The ppmfade command is used to generate a transition between two PPM (Portable Pixmap) images.

Read More