命令(7個)shell
whoami,who,w,last,lastlog,users,fingerbash
12.1.whoamisession
功能:打印有效的用戶名(已登陸的當前shell所在用戶)
ide
語法:whoami [OPTION]...
server
示例:進程
[root@localhost scripts]# whoami #當前用戶爲root
ip
root
terminal
[yyl@localhost ~]$ whoami #當前用戶爲yyl
it
yyl
io
whoami和id -un效果同樣
[yyl@localhost ~]$ id -un
yyl
也能夠分開寫,能夠顯示tty信息,從哪臺機什麼時間什麼ip登錄的
[yyl@localhost ~]$ who am i
yyl pts/1 2017-05-23 14:32 (192.168.19.1)
12.2.who
功能:顯示誰登錄了系統
語法:who [OPTION]... [ FILE | ARG1 ARG2 ]
[yyl@localhost ~]$ who
yyl :0 2017-05-12 22:22 (:0)
yyl pts/0 2017-05-23 11:19 (:0)
yyl pts/1 2017-05-23 14:32 (192.168.19.1)
顯示信息依次爲:用戶名,tty號,時間日期,主機地址
12.3.w
功能:顯示誰登錄了系統而且作了什麼
語法: w - [husfV] [user]
經常使用選項:
-h:不打印頭文件信息
-s:短格式顯示,不打印登錄時間,和JCPU或PCPU時間
[yyl@localhost ~]$ w
14:43:47 up 3:28, 3 users, load average: 0.00, 0.01, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
yyl :0 :0 12May17 ?xdm? 1:48 0.14s gdm-session-worker [pam/gdm-password
yyl pts/0 :0 11:19 3:03m 0.10s 0.57s /usr/libexec/gnome-terminal-server
yyl pts/1 192.168.19.1 14:32 3.00s 0.06s 0.02s w
[yyl@localhost ~]$ w -s
14:48:44 up 3:33, 3 users, load average: 0.00, 0.01, 0.05
USER TTY FROM IDLE WHAT
yyl :0 :0 ?xdm? gdm-session-worker [pam/gdm-password]
yyl pts/0 :0 3:08m /usr/libexec/gnome-terminal-server
yyl pts/1 192.168.19.1 4.00s w -s
輸出的信息包含:
用戶名稱
用戶的機器名稱或tty號
遠程主機地址
用戶登陸系統的時間
空閒時間(做用不大)
附加到tty(終端)的進程所用的時間(JCPU時間)
當前進程所用時間(PCPU時間)
用戶當前正在使用的命令
12.4.last(lastb)
功能:顯示上次登陸的用戶列表(也就是歷史信息)
last跟lastb是同樣的
[yyl@localhost ~]$ last yyl
yyl pts/1 192.168.19.1 Tue May 23 14:32 still logged in
yyl pts/0 :0 Tue May 23 11:19 still logged in
yyl :0 :0 Fri May 12 22:22 still logged in
wtmp begins Sat May 13 06:20:47 2017
顯示信息包含:用戶名,tty設備號, 主機登錄地址,登錄時間,當前狀態,系統總工做時間
12.5.users
功能:打印當前登陸到當前主機用戶的用戶名
語法:users [OPTION]... [FILE]
[yyl@localhost ~]$ users
yyl yyl yyl
登錄的用戶只有yyl,經過不一樣tty登錄
12.6.lastlog
功能:查看全部用戶的最後一次登陸
默認讀取/var/log/lastlog文件內容
示例:
[root@localhost ~]# lastlog
[root@localhost ~]# lastlog -u 500
Username Port From Latest
yyl **Never logged in**
12.7.finger
功能:顯示用戶的相關信息
finger用來顯示用戶名、用戶全名、終端設備號和登陸時間等信息
經常使用選項:
-l 當指定user-list時,默認顯示用戶的詳細信息
-s 當不指定user-list時,默認給出關於每一個用戶的短報告
示例:
[root@localhost ~]# finger #列出當前用戶
Login Name Tty Idle Login Time Office Office Phone
root root pts/0 1:06 Sep 13 11:27 (192.168.19.1)
root root pts/2 Sep 13 13:30 (192.168.19.1)
[root@localhost ~]# finger yyl #列出指定用戶
Login: yyl Name:
Directory: /home/yyl Shell: /bin/bash
Never logged in.
No mail.
No Plan.