The w
is a command-line utility shows the information about currently logged in users. It also displays the system information that how long the system has been running, current time and the system load average. In this guide we will discuss about the w command.
How to Use the w Command
Below is the basic syntax for the w
command:
w [OPTIONS] [USER]
If you run the w
command without any option, it will show the output something like below:
11:14:33 up 2 days, 3:55, 1 user, load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
tecnstuff pts/0 102.102.102.127 11:13 0.00s 0.05s 0.00s w
root pts/0 102.102.102.128 14:08 3.00s 0.04s 0.00s w
In the output, first line shows the information same as the uptime command. Following information are available in that line:
11:14:33
– The current system time.up 2 days, 3:55
– The length of time the system has been up.1 users
– The number of logged-in users.load average: 0.10, 0.08, 0.10
– The system load averages for the past1
,5
, and15
minutes.
In the second line following fields are included:
USER
– It shows the name of the logged in user.TTY
– The name of the terminal used by the user.FROM
– Display the host name or IP address from where the user is logged in.LOGIN@
– It’s time when the user logged in.IDLE
– The time since the user last interacted with the terminal. Idle time.JCPU
– Shows the time used by all processes attached to the tty.PCPU
– Displaying the time used by the user’s current process.WHAT
– The user’s current process and options/arguments.
After that it shows the users list which are logged in with the associated informations. If you will pass the user name with as an argument then it will show the information only about that user.
12:09:07 up 2 days, 4:50, 1 user, load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
tecnstuff pts/0 102.102.102.127 12:08 3.00s 0.04s 0.00s w
w Command Options
You also can pass the options along with the w
command. If you don’t want to print the header you can use -h
, --no-header
option:
w -h
It will show the only information about the logged in users:
tecnstuff pts/0 102.102.102.127 11:13 0.00s 0.05s 0.00s w
root pts/0 102.102.102.128 14:08 3.00s 0.04s 0.00s w
To toggle the FROM
field you should use the -f
, --from
option.
12:26:27 up 2 days, 5:07, 1 user, load average: 0.00, 0.00, 0.00
USER TTY LOGIN@ IDLE JCPU PCPU WHAT
tecnstuff pts/0 12:26 2.00s 0.03s 0.00s w -f
To view output in old style you can use the -o
, --old-style
option. If you use this option, the command prints blank space when IDLE, JCPU, and PCPU times are less than one minute.
12:27:56 up 2 days, 5:09, 1 user, load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
tecnstuff pts/0 102.102.102.127 12:26 w -o
The -s
, --short
option tells w
to use the short style output. When this option is used, the LOGIN@, JCPU, and PCPU fields are not printed
w -s
12:33:25 up 2 days, 5:14, 1 user, load average: 0.00, 0.00, 0.00
USER TTY FROM IDLE WHAT
tecnstuff pts/0 102.102.102.127 1.00s w -s
To show the IP address instead of the host in the FROM field, you should use the -i
, --ip-addr
option.
w -i
12:35:30 up 2 days, 5:16, 1 user, load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
tecnstuff pts/0 102.102.102.127 12:26 1.00s 0.04s 0.00s w -i
Conclusion
Use w command to get the information about the system’s logged in users and activity. To get mroe information about the w command, you can type man w
in your terminal.
If you have any questions, please leave a comment below.