'\" te .\" Copyright 1989 AT&T .\" Copyright (c) 2000, 2011, Oracle and/or its affiliates.All rights reserved. .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation.Original documentation from The Open Group can be obtained online at http://www.opengroup.org/bookstore/. .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation.In the following statement, the phrase"this text" refers to portions of the system documentation.Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group.In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document.The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.This notice shall appear on any product containing this material. .TH who 1 "2011 年 3 月 29 日" "SunOS 5.11" "用户命令" .SH 名称 who \- 显示系统上的用户 .SH 用法概要 .LP .nf \fB/usr/bin/who\fR [\fB-abdHlmpqrstTu\fR] [\fIfile\fR] .fi .LP .nf \fB/usr/bin/who\fR \fB-q\fR [\fB-n\fR \fIx\fR] [\fIfile\fR] .fi .LP .nf \fB/usr/bin/who\fR am i .fi .LP .nf \fB/usr/bin/who\fR am I .fi .LP .nf \fB/usr/xpg4/bin/who\fR [\fB-abdHlmpqrtTu\fR] [\fIfile\fR] .fi .LP .nf \fB/usr/xpg4/bin/who\fR \fB-q\fR [\fB-n\fR \fIx\fR] [\fIfile\fR] .fi .LP .nf \fB/usr/xpg4/bin/who\fR \fB-s\fR [\fB-bdHlmpqrtu\fR] [\fIfile\fR] .fi .LP .nf \fB/usr/xpg4/bin/who\fR am i .fi .LP .nf \fB/usr/xpg4/bin/who\fR am I .fi .SH 描述 .sp .LP \fBwho\fR 实用程序可以列出 UNIX 系统上当前每个用户的用户名、终端行、登录时间、自行上发生活动以来经过的时间和命令解释程序 (shell) 的进程 ID。它将检查 \fB/var/adm/utmpx\fR 文件来获取相关信息。如果指定了 \fIfile\fR,则会检查该文件(必须采用 \fButmpx\fR(4) 格式)。通常,\fIfile\fR 为 \fB/var/adm/wtmpx\fR,其中包含自上次创建文件以来所有登录信息的历史记录。 .sp .LP 常规输出格式如下: .sp .in +2 .nf \fIname\fR [\fIstate\fR] \fIline time\fR [\fIidle\fR] [\fIpid\fR] [\fIcomment\fR] [\fIexit\fR] .fi .in -2 .sp .sp .LP 其中: .sp .ne 2 .mk .na \fB\fIname\fR\fR .ad .RS 11n .rt 用户的登录名 .RE .sp .ne 2 .mk .na \fB\fIstate\fR\fR .ad .RS 11n .rt 向终端写入数据的能力 .RE .sp .ne 2 .mk .na \fB\fIline\fR\fR .ad .RS 11n .rt 在 \fB/dev\fR 中找到的行的名称 .RE .sp .ne 2 .mk .na \fB\fItime\fR\fR .ad .RS 11n .rt 自用户登录以来的时间 .RE .sp .ne 2 .mk .na \fB\fIidle\fR\fR .ad .RS 11n .rt 自用户上次活动以来经过的时间 .RE .sp .ne 2 .mk .na \fB\fIpid\fR\fR .ad .RS 11n .rt 用户的进程 ID .RE .sp .ne 2 .mk .na \fB\fIcomment\fR\fR .ad .RS 11n .rt \fBinittab\fR(4) 中的注释行 .RE .sp .ne 2 .mk .na \fB\fIexit\fR\fR .ad .RS 11n .rt 停用进程的退出状态 .RE .SH 选项 .sp .LP 支持以下选项: .sp .ne 2 .mk .na \fB\fB-a\fR\fR .ad .RS 8n .rt 进程 \fB/var/adm/utmpx\fR 或启用了 \fB-b\fR、\fB-d\fR、\fB-l\fR、\fB-p\fR、\fB-r\fR、\fB-t\fR、\fB-T\fR 和 \fB-u\fR 选项的指定 \fIfile\fR。 .RE .sp .ne 2 .mk .na \fB\fB-b\fR\fR .ad .RS 8n .rt 表示上次重新引导的时间和日期。 .RE .sp .ne 2 .mk .na \fB\fB-d\fR\fR .ad .RS 8n .rt 显示已过期且未通过 \fBinit\fR 重新产生的所有进程。\fBexit\fR 字段针对停用进程显示,并包含停用进程的终止和退出值(由 \fBwait\fR(3C) 返回)。该字段在确定进程终止原因时非常有用。 .RE .sp .ne 2 .mk .na \fB\fB-H\fR\fR .ad .RS 8n .rt 输出常规输出上方的列标题。 .RE .sp .ne 2 .mk .na \fB\fB-l\fR\fR .ad .RS 8n .rt 仅列出等待用户登录的系统所在的行。在这种情况下,\fIname\fR 字段为 \fBLOGIN\fR。其他字段与用户条目的字段相同,只是 \fIstate\fR 字段不存在。 .RE .sp .ne 2 .mk .na \fB\fB-m\fR\fR .ad .RS 8n .rt 仅输出有关当前终端的信息。 .RE .sp .ne 2 .mk .na \fB\fB-n\fR \fIx\fR\fR .ad .RS 8n .rt 接受数字参数 \fIx\fR,用于指定每行显示的用户数。\fIx\fR 必须至少为 \fB1\fR。\fB-n\fR 选项只能与 \fB-q\fR 一起使用。 .RE .sp .ne 2 .mk .na \fB\fB-p\fR\fR .ad .RS 8n .rt 列出当前处于活动状态且之前由 \fBinit\fR 产生的其他所有进程。\fIname\fR 字段显示在 \fB/usr/sbin/inittab\fR 中找到的由 \fBinit\fR 执行的程序的名称。\fIstate\fR、\fIline\fR 和 \fIidle\fR 字段没有意义。\fIcomment\fR 字段显示 \fB/usr/sbin/inittab\fR 中产生该进程的行的 \fBid\fR 字段。请参见 \fBinittab\fR(4)。 .RE .sp .ne 2 .mk .na \fB\fB-q\fR\fR .ad .RS 8n .rt (快速执行 \fBwho\fR)仅显示当前登录系统的用户的名称和数目。如果使用了该选项,将忽略其他所有选项。 .RE .sp .ne 2 .mk .na \fB\fB-r\fR\fR .ad .RS 8n .rt 表示 \fBinit\fR 进程的当前 \fIrun-level\fR。 .RE .sp .ne 2 .mk .na \fB\fB-s\fR\fR .ad .RS 8n .rt (缺省值)仅列出 \fIname\fR、\fIline\fR 和 \fItime\fR 字段。 .RE .SS "/usr/bin/who" .sp .ne 2 .mk .na \fB\fB-T\fR\fR .ad .RS 6n .rt 与 \fB-s\fR 选项相同,只是也写入 \fIstate\fR \fIidle\fR、\fIpid\fR 和 \fIcomment\fR 字段。\fIstate\fR 是以下字符之一: .sp .ne 2 .mk .na \fB\fB+\fR\fR .ad .RS 5n .rt 终端允许授予其他用户写入权限。 .RE .sp .ne 2 .mk .na \fB\fB-\fR\fR .ad .RS 5n .rt 终端拒绝授予其他用户写入权限。 .RE .sp .ne 2 .mk .na \fB\fB?\fR\fR .ad .RS 5n .rt 无法确定终端写入访问权限状态。 .RE .RE .SS "/usr/xpg4/bin/who" .sp .ne 2 .mk .na \fB\fB-T\fR\fR .ad .RS 6n .rt 与 \fB-s\fR 选项相同,只是也写入 \fIstate\fR 字段。\fIstate\fR 是该选项的 \fB/usr/bin/who\fR 版本下所示字符之一。如果将 \fB-u\fR 选项与 \fB-T\fR 一起使用,会将空闲时间添加到前一种格式的结尾。 .RE .sp .ne 2 .mk .na \fB\fB-t\fR\fR .ad .RS 6n .rt 表示 \fBroot\fR 上次对系统时钟的更改(使用 \fBdate\fR 实用程序)。请参见 \fBsu\fR(1M) 和 \fBdate\fR(1)。 .RE .sp .ne 2 .mk .na \fB\fB-u\fR\fR .ad .RS 6n .rt 仅列出当前登录系统的用户。\fIname\fR 是用户的登录名。\fIline\fR 是在目录 \fB/dev\fR 中找到的行的名称。\fItime\fR 是用户登录的时间。\fIidle\fR 列包含该特定行上自上次发生活动以来经过的小时和分钟数。点 (\fB\&.\fR) 表示上一分钟在终端上发生了活动,因此当前正在进行。如果经过的时间超过了二十四小时或者自引导以来未曾使用该行,则会将条目标记为 \fBold\fR。该字段在尝试确定某个用户是否在终端上执行操作时非常有用。\fIpid\fR 是用户 shell 的进程 ID。\fIcomment\fR 是在 \fB/usr/sbin/inittab\fR(请参见 \fBinittab\fR(4))中找到的与该行关联的注释字段。其中可包含有关终端所在位置、数据集的电话号码、终端类型(如果采用硬接线)等方面的信息。 .RE .SH 操作数 .sp .LP 支持下列操作数: .sp .ne 2 .mk .na \fB\fBam\fR \fBi\fR\fR .ad .br .na \fB\fBam\fR \fBI\fR\fR .ad .RS 8n .rt 在 C 语言环境中,仅限输出描述正在调用的用户,等效于 \fB-m\fR 选项。\fBam\fR 和 \fBi\fR 或 \fBI\fR 必须是单独的参数。 .RE .sp .ne 2 .mk .na \fB\fIfile\fR\fR .ad .RS 8n .rt 指定用来替换 \fBwho\fR 在缺省情况下所用登录系统的用户数据库的文件的路径名。 .RE .SH 环境变量 .sp .LP 有关影响 \fBwho\fR 执行的环境变量 \fBLANG\fR、\fBLC_ALL\fR、\fBLC_CTYPE\fR、\fBLC_MESSAGES\fR、\fBLC_TIME\fR 和 \fBNLSPATH\fR 的说明,请参见 \fBenviron\fR(5)。 .SH 退出状态 .sp .LP 将返回以下退出值: .sp .ne 2 .mk .na \fB\fB0\fR\fR .ad .RS 6n .rt 成功完成。 .RE .sp .ne 2 .mk .na \fB\fB>0\fR\fR .ad .RS 6n .rt 出现错误。 .RE .SH 文件 .sp .ne 2 .mk .na \fB\fB/usr/sbin/inittab\fR\fR .ad .RS 21n .rt \fBinit\fR 的脚本 .RE .sp .ne 2 .mk .na \fB\fB/var/adm/utmpx\fR\fR .ad .RS 21n .rt 当前用户和计帐信息 .RE .sp .ne 2 .mk .na \fB\fB/var/adm/wtmpx\fR\fR .ad .RS 21n .rt 历史用户和计帐信息 .RE .SH 属性 .sp .LP 有关下列属性的说明,请参见 \fBattributes\fR(5): .SS "/usr/bin/who" .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . 属性类型属性值 _ 可用性system/core-os .TE .SS "/usr/xpg4/bin/who" .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . 属性类型属性值 _ 可用性system/xopen/xcu4 _ 接口稳定性Committed(已确定) _ 标准请参见 \fBstandards\fR(5)。 .TE .SH 另请参见 .sp .LP \fBdate\fR(1)、\fBlogin\fR(1)、\fBmesg\fR(1)、\fBinit\fR(1M)、\fBsu\fR(1M)、\fBwait\fR(3C)、\fBinittab\fR(4)、\fButmpx\fR(4)、\fBattributes\fR(5)、\fBenviron\fR(5)、\fBstandards\fR(5) .SH 附注 .sp .LP \fB超级用户:\fR关闭单用户状态后,\fBwho\fR 将返回提示符。由于 \fB/var/adm/utmpx\fR 在登录时进行更新而且在单用户状态下没有登录信息,因此 \fBwho\fR 无法准确地报告该状态。但是,命令 \fBwho\fR \fBam i\fR 可以返回正确的信息。