UNIX/Linux列出当前登录的用户
时间:2020-01-09 10:46:01 来源:igfitidea点击:
如何从命令提示符下打印当前登录到当前UNIX/Linux主机/服务器的用户的用户名?
您需要使用以下任一工具。
w命令显示有关机器上当前用户及其进程的信息。who命令显示有关当前登录用户的信息。users命令显示系统上当前用户的登录名,以排序方式显示,并以空格分隔。
它从/var/run/utmp文件读取所有信息。
例子
打开一个终端(或者使用ssh命令登录到远程服务器)并执行以下命令。
w命令
输入w命令:
$ w
输出示例:
w命令正在起作用。
要查看有关名为tom的用户的信息,请执行:
# w tom
who命令
who命令可在所有Unix之类的操作系统上运行:
# who
输出示例:
root pts/0 2013-03-12 15:10 (10.1.3.177)
将-a选项传递给who命令:
# who -a
输出示例:
system boot 2013-03-02 04:10
run-level 3 2013-03-02 04:10
LOGIN /dev/ttyS1 2013-03-02 04:11 7951 id=v/tt
LOGIN tty2 2013-03-02 04:11 7953 id=2
LOGIN tty1 2013-03-02 04:11 7950 id=1
LOGIN tty3 2013-03-02 04:11 7955 id=3
LOGIN tty4 2013-03-02 04:11 7957 id=4
LOGIN tty5 2013-03-02 04:11 7959 id=5
LOGIN tty6 2013-03-02 04:11 7961 id=6
root + pts/0 2013-03-12 15:10 . 7451 (10.1.3.177)
pts/1 2013-03-08 12:29 23510 id=ts/1 term=0 exit=0
其他选项
您可以将以下选项传递给who命令:
Just open a -a, --all same as -b -d --login -p -r -t -T -u
-b, --boot time of last system boot
-d, --dead print dead processes
-H, --heading print line of column headings
-l, --login print system login processes
--lookup attempt to canonicalize hostnames via DNS
-m only hostname and user associated with stdin
-p, --process print active processes spawned by init
-q, --count all login names and number of users logged on
-r, --runlevel print current runlevel
-s, --short print only name, line, and time (default)
-t, --time print last system clock change
-T, -w, --mesg add user's message status as +, - or ?
-u, --users list users logged in
--message same as -T
--writable same as -T
--help display this help and exit
--version output version information and exit
users命令
打开终端或者登录ssh会话并输入以下命令:
$ users
输出示例:
abhi charvi Hyman Hyman zcafe

