回到手册索引

命令用途

w 命令用于显示当前登录系统的用户信息及其正在执行的进程,包括用户、终端、来源 IP、登录时间、空闲时间及活动进程等。

常用用法示例

  1. 默认显示所有登录用户及活动

    1
    2
    3
    4
    5
    w
    12:34:56 up 1:23, 3 users, load average: 0.00, 0.01, 0.05
    USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
    user1 pts/0 192.168.1.10 11:15 5.00s 0.10s 0.00s sshd: user1
    user2 tty2 :0 10:30 2:00m 1:20 0.02s /usr/bin/bash

    显示当前所有登录用户的详细信息,包括终端、来源、空闲时间及运行命令。

  2. 仅显示指定用户的信息

    1
    2
    3
    4
    w user1
    12:34:56 up 1:23, 3 users, load average: 0.00, 0.01, 0.05
    USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
    user1 pts/0 192.168.1.10 11:15 5.00s 0.10s 0.00s sshd: user1

    仅输出用户 user1 的登录信息。

  3. 短格式显示(隐藏登录时间和 JCPU/PCPU)

    1
    2
    3
    4
    5
    w -s
    12:34:56 up 1:23, 3 users, load average: 0.00, 0.01, 0.05
    USER TTY FROM IDLE WHAT
    user1 pts/0 192.168.1.10 5.00s sshd: user1
    user2 tty2 :0 2:00m /usr/bin/bash

    简化输出,省略 LOGIN@、JCPU 和 PCPU 列。

  4. 不显示标题头

    1
    2
    3
    w -h
    user1 pts/0 192.168.1.10 11:15 5.00s 0.10s 0.00s sshd: user1
    user2 tty2 :0 10:30 2:00m 1.20s 0.02s /usr/bin/bash

    隐藏输出的标题行(如 USER、TTY 等)。

  5. 强制显示 IP 地址而非主机名

    1
    2
    3
    w -i
    USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
    user1 pts/0 192.168.1.10 11:15 5.00s 0.10s 0.00s sshd: user1

    在 FROM 列中显示 IP 地址而非主机名(若支持)。

  6. 显示特定用户的进程信息

    1
    2
    3
    w -u user2
    USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
    user2 tty2 :0 10:30 2:00m 1.20s 0.02s /usr/bin/bash

    仅显示 user2 的进程信息(类似 w user2)。

  7. 指定输出的列顺序

    1
    2
    3
    w -o "user tty from idle what"
    USER TTY FROM IDLE WHAT
    user1 pts/0 192.168.1.10 5.00s sshd: user1

    自定义输出列的顺序和内容。

  8. 显示版本信息

    1
    2
    w -V
    w from procps-ng 3.3.17

    输出 w 命令的版本信息。

常用参数选项

  • -h, –no-header
    不显示标题行(如 USER、TTY 等列名)。
  • -s, –short
    使用短格式输出,隐藏 LOGIN@、JCPU 和 PCPU 列。
  • -u, –user
    仅显示指定用户的登录信息(如 w -u user1)。
  • -f, –from
    切换是否显示 FROM 列(部分系统默认隐藏该列)。
  • -i, –ip-addr
    在 FROM 列中显示 IP 地址而非主机名。
  • -o, –output <字段>
    自定义输出字段及顺序(如 -o “user tty from”)。
  • -V, –version
    显示 w 命令的版本信息。
  • –help
    显示帮助文档,列出所有参数选项。

原厂文档

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
NAME

w - Show who is logged on and what they are doing.

SYNOPSIS

w [option ...] [user]

DESCRIPTION

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 minutes.

The following entries are displayed for each user: login name, the
tty name, the remote host, login time, idle time, JCPU, PCPU, and
the command 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 "what" field.

OPTIONS

-c, --container
show the container uptime instead of system uptime in the
header.

-h, --no-header
Don't print the header.

-u, --no-current
Ignores 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.

-s, --short
Use the short format. Don't print the login time, JCPU or
PCPU times.

-f, --from
Toggle 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
field is shown by default.

--help Display help text and exit.

-i, --ip-addr
Display IP address instead of hostname for from field.

-p, --pids
Display pid of the login process/the "what" process in the
"what" field.

-V, --version
Display version information.

-o, --old-style
Old style output. Prints blank space for idle times less
than one minute.

user Show information about the specified user only.

ENVIRONMENT

PROCPS_CONTAINER
If $PROCPS_CONTAINER is set, then w behaves as if the
--container option has been given.

PROCPS_USERLEN
Override the default width of the username column.
Defaults to 8.

PROCPS_FROMLEN
Override the default width of the from column. Defaults to
16.

FILES

/var/run/utmp
information about who is currently logged on, only for non-
systemd hosts.

/proc process information

SEE ALSO

free(1), loginctl(1), ps(1), top(1), uptime(1), utmp(5), who(1)

AUTHORS

w was re-written almost entirely by Charles Blake, based on the
version by Larry Greenfield ⟨greenfie@gauss.rutgers.edu⟩ and
Michael K. Johnson ⟨johnsonm@redhat.com⟩.

REPORTING BUGS

Please send bug reports to ⟨procps@freelists.org⟩.

COLOPHON

This page is part of the procps-ng (/proc filesystem utilities)
project. Information about the project can be found at
⟨https://gitlab.com/procps-ng/procps⟩. If you have a bug report
for this manual page, see
⟨https://gitlab.com/procps-ng/procps/blob/master/Documentation/bugs.md⟩.
This page was obtained from the project's upstream Git repository
⟨https://gitlab.com/procps-ng/procps.git⟩ on 2024-02-02. (At that
time, the date of the most recent commit that was found in the
repository was 2024-01-15.) If you discover any rendering
problems in this HTML version of the page, or you believe there is
a better or more up-to-date source for the page, or you have
corrections or improvements to the information in this COLOPHON
(which is not part of the original manual page), send a mail to
man-pages@man7.org