who:显示系统当前所有登录会话
[root@bash ~]# who root tty1 2016-12-27 21:23 root pts/0 2016-12-28 19:23 (192.168.1.116) root tty2 2016-12-28 07:43w:系统当前所有的登录会话以及所做操作
[root@bash ~]# w 20:22:25 up 15:55, 3 users, load average: 0.00, 0.01, 0.05 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root tty1 Tue21 15:27m 0.09s 0.09s -bash root pts/0 192.168.1.116 19:23 1.00s 0.12s 0.01s w root tty2 07:43 19:29 0.02s 0.02s -bashwhoami:显示当前系统登录用户
[root@bash ~]# whoami rootlast: show listing of last logged in users
[root@bash ~]# last root pts/0 192.168.1.116 Wed Dec 28 19:23 still logged in root tty2 Wed Dec 28 07:43 still logged in root pts/0 192.168.1.116 Wed Dec 28 06:32 - 19:23 (12:50) root pts/1 192.168.1.116 Wed Dec 28 02:12 - 05:24 (03:12) root pts/1 192.168.1.116 Wed Dec 28 02:11 - 02:12 (00:00) root pts/1 192.168.1.116 Wed Dec 28 01:19 - 02:11 (00:51) root pts/1 192.168.1.116 Wed Dec 28 01:18 - 01:19 (00:01 [root@bash ~]# last -n2 #显示行数为2行 root pts/0 192.168.1.116 Wed Dec 28 19:23 still logged in root tty2 Wed Dec 28 07:43 still logged [root@bash ~]# last -20 #从后倒数显示 root pts/0 192.168.1.116 Wed Dec 28 19:23 still logged in root tty2 Wed Dec 28 07:43 still logged in root pts/0 192.168.1.116 Wed Dec 28 06:32 - 19:23 (12:50) root pts/1 192.168.1.116 Wed Dec 28 02:12 - 05:24 (03:12) root pts/1 192.168.1.116 Wed Dec 28 02:11 - 02:12 (00:00) ...lastlog:reports the most recent login of all users or of a given user
-b, --before DAYS print only lastlog records older than DAYS -h, --help display this help message and exit -R, --root CHROOT_DIR directory to chroot into -t, --time DAYS print only lastlog records more recent than DAYS -u, --user LOGIN print lastlog record of the specified LOGIN [root@bash ~]# lastlog #显示所有用户记录 Username Port From Latest root pts/0 192.168.1.116 Wed Dec 28 19:23:08 +0800 2016 bin **Never logged in** daemon **Never logged in** adm **Never logged in** lp **Never logged in** sync **Never logged in** ... [root@bash ~]# lastlog -u root #显示root用户登录记录 Username Port From Latest root pts/0 192.168.1.116 Wed Dec 28 19:23:08 +0800 2016注:
lastlog 只是读出 /var/log/lastlog 内的信息
last 预设读出 /var/log/wtmp 这个档案,但是我们可以透过 -f 读取不同的登录文件信
实例:last -f /PATH/TO/LOG_NAME/
三、关机重启相关命令shutdown,reboot,halt,poweroff