Linux w Command Tutorial for Beginners (5 Examples)
If you are new to Linux system administration, you should be aware of tools that help you in user management. One such utility is w, which shows info about users that are currently logged in to a system, including what they are doing. In this article, we will discuss this tool using some easy to understand examples.
But before we do that, it's worth mentioning that all examples here have been tested on an Ubuntu 16.04 LTS machine.
Linux w command
As already mentioned above, w displays information related to users that are currently logged in. Following is its syntax:
w [options] user [...]
And here's how the tool's man page explains it:
w displays information about the users currently on the machine, and
their processes. The header shows, in this order, the current time,
how long the system has been running, how many users are currently
logged on, and the system load averages for the past 1, 5, and 15 min?
The following entries are displayed for each user: login name, the tty
name, the remote host, login time, idle time, JCPU, PCPU, and the com?
mand line of their current process.
The JCPU time is the time used by all processes attached to the tty.
It does not include past background jobs, but does include currently
running background jobs.
The PCPU time is the time used by the current process, named in the
Following are some Q&A-styled examples that should give you a good idea on how the w command works.
Q1. How to use w command?
Basic usage is very easy - all you have to do is to execute 'w' sans any options.
Following is the output the 'w' command produced on my system:
For details on what the different fields in the output mean, refer to the introduction section of the tutorial above.
Q2. How to make w command strip header?
If you don't want w to display the header in output, use the -h command line option.
So you can see the header was stripped off in the output.
Q3. How to make w display output in short format?
If you want w to display output in short format, use the -s option. In this format, the output doesn't contain the login time, JCPU or PCPU times.
Q4. How to make w not display the FROM field?
This can be made possible using the -f command line option.
Here's the output this command produced on my system:
So you can see the FROM field is missing from the output. Note that you can use the -i command line option in case you want w to display IP address instead of hostname for the FROM field.
Q5. How to make w print info for a specific user?
This can be achieved by passing the corresponding user name as input to the w command. For example, if you want w to only display info related to user 'himanshu', run the w command in the following way:
The w command is a useful little tool that doesn't have a steep learning curve. In fact, the utility is easy to understand and use. We've discussed almost all major options here. For more information on the tool, head to its man page.