百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术文章 > 正文
Linux系统 用户信息的显示:users、w、who

Linux系统 用户信息的显示:users、w、who

  • 网站名称:Linux系统 用户信息的显示:users、w、who
  • 网站分类:技术文章
  • 收录时间:2025-07-16 15:46
  • 网站地址:

进入网站

“Linux系统 用户信息的显示:users、w、who” 网站介绍

前言


在Linux系统中,当我们需要查看登入系统的用户相关信息的时候,可以通过如下三条命令来查看:【 users | w | who 】。

本文来具体学习一下这三条命令。


目录

一、命令描述

二、命令常用选项

三、命令演示

四、总结

五、补充


一、命令描述

1、作用:

  • users:显示当前系统中已登入的所有用户。
  • w:显示当前系统中已登入的所有用户以及他们的动作。
  • who:显示当前系统中已登入的所有用户以及他们的具体信息。

2、格式:

  • users:users [选项]
  • w:w [选项] [用户名]
  • who:who [选项]


二、命令常用选项

1、users:

  • [ --help ]:显示帮助信息
  • [ --version ]:显示版本信息

2、w:

  • [ h ]:不打印标题。
  • [ -s ]:简化形式,去掉登入时间、JCPU、PJPU。
  • [ -f ]:不打印FROM字段,(FROM字段:用户从哪登录)。
  • <username>:显示指定用户的相关信息。

3、who

  • [ -a ]:显示所有具体信息,包括用户名、运行级别、登录时间、PID和备注等。
  • [ -b ]:显示上次系统启动的时间。
  • [ -d ]:打印死亡进程。
  • [ -H ]:显示标题。
  • [ -m ]:只打印当前用户的信息。
  • [ -q ]:计算并输出用户的用户名和数量信息。
  • [ -r ]:打印当前用户使用运行级别。
  • [ -s ]:只显示用户的用户名、登录时间、备注信息。
  • [ -t ]:打印上一次系统时间改变的时间。


三、命令演示

1、练习一:查看帮助信息

  • 打开users、w、who命令的帮助信息。
[root@localhost lmh]# users --help
Usage: users [OPTION]... [FILE]
Output who is currently logged in according to FILE.
If FILE is not specified, use /var/run/utmp.  /var/log/wtmp as FILE is common.

      --help     display this help and exit
      --version  output version information and exit

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'users invocation'

[root@localhost lmh]# w --help

Usage:
 w [options]

Options:
 -h, --no-header     do not print header
 -u, --no-current    ignore current process username
 -s, --short         short format
 -f, --from          show remote hostname field
 -o, --old-style     old style output
 -i, --ip-addr       display IP address instead of hostname (if possible)

     --help     display this help and exit
 -V, --version  output version information and exit

For more details see w(1).

[root@localhost lmh]# who --help
Usage: who [OPTION]... [ FILE | ARG1 ARG2 ]
Print information about users who are currently logged in.

  -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

If FILE is not specified, use /var/run/utmp.  /var/log/wtmp as FILE is common.
If ARG1 ARG2 given, -m presumed: 'am i' or 'mom likes' are usual.

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'who invocation'

2、练习二:

  • 使用users命令查看当前系统运行的用户都有哪些
[root@localhost lmh]# users
lmh lmh root root

3、练习三:

  • 使用w命令查看当前系统所有登入用户的简要信息
[root@localhost lmh]# w
 16:04:15 up 35 min,  4 users,  load average: 0.00, 0.01, 0.05
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    192.168.28.1     15:28   18:07   0.10s  0.00s less -s
root     pts/1    192.168.28.1     15:33    7.00s  0.31s  0.05s w
lmh      pts/2    192.168.28.1     15:35   12:15   0.05s  0.05s -bash
lmh      pts/3    192.168.28.1     15:49   14:15   0.04s  0.04s -bash
[root@localhost lmh]# w -s
 16:04:17 up 35 min,  4 users,  load average: 0.00, 0.01, 0.05
USER     TTY      FROM              IDLE WHAT
root     pts/0    192.168.28.1     18:09  less -s
root     pts/1    192.168.28.1      1.00s w -s
lmh      pts/2    192.168.28.1     12:17  -bash
lmh      pts/3    192.168.28.1     14:17  -bash

4、练习四:

  • 使用who命令及其选项[-aH]显示当前系统已登录用户的详细信息并显示标题
[root@localhost lmh]# who -aH
NAME       LINE         TIME                     IDLE          PID COMMENT  EXIT
           system boot  2020-06-05 15:28
           run-level 3    2020-06-05 15:28
LOGIN      tty1         2020-06-05 15:28                 1177 id=tty1
root     + pts/0        2020-06-05 15:28 00:21        1795 (192.168.28.1)
root     + pts/1        2020-06-05 15:33     .            1922 (192.168.28.1)
lmh      + pts/2        2020-06-05 15:35 00:15        2087 (192.168.28.1)
lmh      + pts/3        2020-06-05 15:49 00:17        2329 (192.168.28.1)

四、总结

我们可以通过【users, w, who】这三条命令查看系统登入用户的登录信息。其中,users命令最为简单,只显示用户名称;w命令显示的更详细些,主要用户查看当前用户正在进行的动作以及CPU的工作情况,还可以查看用户登录的IP地址;who命令相对于w命令则多了用户的进程号以及系统运行级别,但是缺少了CPU的工作信息。


五、补充

  1. 我们可以在w, who命令中看到【pts/0】这种类似序号一样的信息,本人上网查阅资料后得到以下结论:pts代表虚拟终端的意思,后面的数字则代表终端的序号。
  2. tty:用户使用的界面,tty1~6代表字符界面,tty7代表图形界面。
  3. JCPU:与该tty终端连接的所有进程使用的时间,过去的后台作业时间除外。
  4. PCPU:当前进程所占用的时间。