The w Command

The w command shows who is logged in to the system and what they are doing.

A login, logging in or logging on is the entering of identifier information into a system by a user in order to access that system (e.g., a computer or a website). It generally requires the user to enter two pieces of information, first a user name and then a password.

The basic syntax of w is:

w [options] [username1, username2, . . .]

The square brackets indicated that the enclosed items are optional. When used without any options, w sends to standard output (which is by default the display screen) a header line followed by a table that contains a line of data for each user currently logged in.

The header shows six items: the current time, how long the system has been running (in minutes) since it was booted up (i.e., started up), how many users are currently logged on, and the system load averages, i.e., the average number of processes active, during the last one, five and 15 minutes. A process is an executing (i.e., running) instance of a program.

The main part of w's output consists of a table showing eight items of information for each user currently logged into the system. The eight columns are labeled USER, TTY, FROM, LOGIN@, IDLE, JCPU, PCPU and WHAT.

USER is the login name of the user. TTY (which now stands for terminal type but originally stood for teletype) is the name of the console or terminal (i.e., combination of monitor and keyboard) that the user logged into, which can also be found by using the tty command. Every time a user logs in across the network, a new tty is assigned to that user.

The consoles can be real or virtual. A feature of Linux systems is the use of virtual consoles, which act as independent logical consoles that run in separate login sessions, but which are accessed from the same physical console (i.e., the same keyboard and screen). That is, each virtual console can have a different, or the same, user logged into it. On a Red Hat system, seven virtual consoles are configured and active by default.

FROM is the remote host (i.e., the name of some other computer), if any, that the user logged into. LOGIN@ is the time at which the user logged in. IDLE is the number of hours and minutes since the user last typed anything at the keyboard.

JCPU is the number of minutes accumulated by all processes attached to the tty. It does not include past background processes (i.e., low priority processes that operate only in gaps between higher priority foreground processes), but it does include currently running background processes.

PCPU is the time consumed by the current process, named in the WHAT column. WHAT lists the name of the current process along with any options and arguments (i.e., input files) used with the command that launched it.

Among the more useful of w's few options is -h, which tells it to omit the header header line from its output. The -s option tells it to use the short format, which omits the login time, JCPU and PCPU columns. The -l option creates a long listing, which is the same as the default. The -V option displays the version number of the currently installed w program.

By default, w reports on all users. However, it can be made to report on only a specified set of users by providing those usernames in a comma-separated list.

w provides information similar to that which would be provided by a combination of the uptime, who and ps -a commands. uptime produces a single line of output that is the same as w's header line. who shows who is currently logged into the system. ps -a lists all processes with a tty except session leaders (i.e., processes that created sessions).

w can be useful, but there are some faults with the information it provides, and thus its output should only be considered approximate. In particular, the notion of the current process is unclear and there are some problems detecting background processes, even though they usually account for much of the load on the system. Also, the CPU time is only an estimate; for example, if a user leaves a background process running after logging out, the time is credited to the person currently on that terminal.

w shows information only for those users who have logged in through a console (i.e., a full-screen text-only display) or a graphical user interface (GUI) login window, and it does not show data for users who have logged in through a terminal window (i.e., a window in a GUI that emulates a console).

w is part of the procps package, which contains several small utilities that provide information about processes using the /proc filesystem. The package also includes the free, kill, ps, skill, slabtop, top and vmstat programs.

The home page of procps is

Created May 9, 2005.
Copyright © 2005 The Linux Information Project. All Rights Reserved.