Linux w command with Examples

w command in Linux is utilized to show who is signed on and what they are doing. This command shows the data about the users right now on the machine and their processes. The header shows, in a specific order, the current time, how long the system has been running, the number of users are right now signed on, and the system load averages for as far back as 1, 5, and 15 minutes. The accompanying passages are shown for every client: login name, the tty name, the distant host, login time, inactive time, JCPU, PCPU, and the order line of their present interaction. The JCPU time is the time utilized by all cycles joined to the tty. It does exclude past background jobs however incorporates right now running background jobs. The PCPU time is the time utilized by the current process, named in the “what” field.

Linux w command with Examples

Linux w command with Examples:

Command-Line Options:

TagDescription
-hDon’t print the header.
-uIgnores the username while figuring out the current process and CPU times. To demonstrate this, do a “su” and do a “w” and a “w -u”.
-sUse the short format. Don’t print the login time, JCPU, or PCPU times.
-fToggle printing the from (remote hostname) field. The default as released is for the from field to not be printed, although your system administrator or distribution maintainer may have compiled a version in which the from the field is shown by default.
-VDisplay version information.
user
Show information about the specified user only.

 Syntax:

w [options] user [...]

The w command gives information data about right now logged-in users.

$ w

11:24:37 up  2:04,  1 user,  load average: 2.04, 1.95, 1.74
USER          TTY      FROM             [email protected]   IDLE   JCPU   PCPU WHAT
itsmarttricks tty7     :0               09:21    2:04m  7:52   0.52s xfce4-session

The first line provides the same information as the uptime command. It contains the following columns:

11:24:37– The current system time.2:04 – The length of time the system has been up.1 user – The number of logged-in users.2.04, 1.95, 1.74 – The system load averages for the past 1, 5, and 15 minutes. The system load average is a measurement of the number of jobs that are currently running or waiting for disk I/O. It basically tells you how busy your system has been over the given interval.
The second line includes the following fields:

The second line includes the following fields:

  1. USER – The name of the logged user.
  2. TTY – The name of the terminal used by the user.
  3. FROM – The hostname or IP address from where the user is logged in.
  4. [email protected] – The time when the user logged in.
  5. IDLE – The time since the user last interacted with the terminal. Idle time.
  6. JCPU – The time used by all processes attached to the tty.
  7. PCPU – The time used by the user’s current process. The one displayed in the field.
  8. WHAT – The user’s current process and options/arguments.

The command at that point records all as of now signed-in users and the information related to them.

On the off chance that you pass at least one user names as contentions to the w command, the yield is restricted to the given users:

$ w itsmarttricks

11:25:50 up  5:04,  1 user,  load average: 2.04, 1.95, 1.74
USER          TTY      FROM    [email protected]   IDLE   JCPU   PCPU WHAT
itsmarttricks tty7     :0       09:21    2:04m  7:52   0.52s xfce4-session

w pulls data about the signed-in clients from the /var/run/utmp file

w Command Options:

w accepts several options that are rarely used.

The -h--no-header option tells w not to print the header:

w -h

Only the information about the logged in users is printed:

root pts/0 10.10.0.2 20:59 1.00s 0.02s 0.00s w -h
itsmarttricks pts/1 10.10.0.8 21:41 7.00s 0.00s 0.00s bash

The -f--from option toggles the FROM field. Whether this filed is shown or hidden by default depend on the distribution you’re using

w -f
22:48:39 up 12 days, 11:15,  2 users,  load average: 0.03, 0.02, 0.00
USER      TTY        [email protected]   IDLE   JCPU   PCPU WHAT
root      pts/0     20:59    5.00s  0.03s  0.01s bash
itsmarttricks pts/1     21:41    1.00s  0.02s  0.00s w -f

The -o--old-style option, tells w to use the old-style output. When this option is used, the command prints blank space when IDLEJCPU, and PCPU times are less than one minute.

w -o
22:50:33 up 12 days, 11:17,  2 users,  load average: 0.14, 0.04, 0.01
USER      TTY      FROM        [email protected]   IDLE   JCPU   PCPU WHAT
root      pts/0    10.10.0.2   20:59    1:59m               bash
itsmarttricks  pts/1    10.10.0.8   21:41                        w -o

The -s--short option tells w to use the short style output. When this option is used, the [email protected]JCPU, and PCPU fields are not printed.

w -s
 22:51:48 up 12 days, 11:18,  2 users,  load average: 0.04, 0.03, 0.00
USER      TTY      FROM         IDLE WHAT
root      pts/0    10.10.0.2    3:14  bash
itsmarttricks  pts/1    10.10.0.8    2.00s w -s

The -i--ip-addr option forces w to always show IP address instead of the hostname in the FROM field.

Also Read – Learn Basic Linux System Commands For Linux Foundation Certified IT Associate (LFCA) Certification

That’s all, In this article, we have explained the Linux w command with Examples. I hope you enjoy this article. If you like this article, then just share it and then do subscribe to email alerts for Linux, Windows, macOS, Android, Internet, Firewall and Security, CCTV tutorials. If you have any questions or doubts about this article, please comment.

Share this:

Related Posts