linux-查看當前登錄的用戶


1、w命令查看當前用戶
[root@iZuf654dlv34jnzeptn4gmZ test]# 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


[root@iZuf654dlv34jnzeptn4gmZ test]# w
 10:35:02 up 134 days, 10:52,  2 users,  load average: 0.01, 0.06, 0.06
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     tty1                      056月17 134days  0.01s  0.01s -bash
root     pts/0    116.226.109.51   10:30    6.00s  0.03s  0.00s w


命令信息含義上述顯示的信息分別表示如下:

第一行顯示系統的彙總信息,字段分別表示系統當前時間、系統運行時間、登陸系統用戶總數及系統平均負載信息。對於如上圖顯示的字段意義爲:


10:35:02表示執行w的時間是在上午10點35分02秒。

up 134 days, 10:52 表示系統運行134天10小時52分。


2 users 表示當前系統登陸用戶總數爲3。

Load average 與後面的數字一起表示系統在過去1,5,10分鐘內的負載程度,數值越小,系統負載越輕。

從第二行開始構成一個登錄用戶信息列表,共有8個欄目,分別顯示各個用戶正在做的事情及該用戶所佔用的系統資源。

USER:顯示登陸用戶帳號名。用戶重複登陸,該帳號也會重複出現。

TTY:用戶登陸所用的終端。

FROM:顯示用戶在何處登陸系統。

LOGIN@:是LOGIN AT的意思,表示登陸進入系統的時間。

IDLE:用戶空閒時間,從用戶上一次任務結束後,開始記時。

JCPU:以終端代號來區分,表示在這段時間內,所有與該終端相關的進程任務所耗費的CPU時間。

PCPU:指WHAT域的任務執行後耗費的CPU時間。

WHAT:表示當前執行的任務。

2、who命令查看當前用戶
[root@iZuf654dlv34jnzeptn4gmZ test]# man who
NAME
       who - show who is logged on
SYNOPSIS
       who [OPTION]... [ FILE | ARG1 ARG2 ]
DESCRIPTION
       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


[root@iZuf654dlv34jnzeptn4gmZ test]# who
root     tty1         2017-06-05 23:42
root     pts/0        2017-10-18 10:30 (116.226.109.51)

[root@iZuf654dlv34jnzeptn4gmZ test]# who -a
           系統引導 2017-06-06 07:42
root     + tty1         2017-06-05 23:42  舊的         482
           運行級別 3 2017-06-05 23:42
root     + pts/0        2017-10-18 10:30   .          4993 (116.226.109.51)
           pts/1        2017-06-29 17:37              3961 id=ts/1  終端=0 退出=0
           pts/2        2017-09-24 01:38             24836 id=ts/2  終端=0 退出=0
           pts/3        2017-06-06 03:15              2276 id=ts/3  終端=0 退出=0
[root@iZuf654dlv34jnzeptn4gmZ test]# who -b
         系統引導 2017-06-06 07:42


[root@iZuf654dlv34jnzeptn4gmZ test]# who -HT
名稱     線路       時間           備註
root     + tty1         2017-06-05 23:42
root     + pts/0        2017-10-18 10:30 (116.226.109.51)
who -T 就可以得到該用戶是否願意接受其他用戶信息(-T)還可以顯示空閒時間(-I)及標題欄(-H)。
如果某個用戶願意接受信息,會在MESG欄中顯示一個“+”,這時還可以使用命令MESG給用戶發從信息。

3、whoami命令查看當前用戶
[root@iZuf654dlv34jnzeptn4gmZ test]# whoami
root



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章