00. 目录
01. 命令概述
lastlog命令用于显示系统中所有用户最近一次登录信息。
lastlog文件在每次有用户登录时被查询。可以使用lastlog命令检查某特定用户上次登录的时间,并格式化输出上次登录日志/var/log/lastlog
的内容。它根据UID排序显示登录名、端口号(tty)和上次登录时间。如果一个用户从未登录过,lastlog显示**Never logged**
。注意需要以root身份运行该命令。
02. 命令格式
用法:lastlog [选项]
03. 常用选项
选项:
-b, --before DAYS 仅打印早于 DAYS 的最近登录记录
-C, --clear clear lastlog record of an user (usable only with -u)
-h, --help 显示此帮助信息并推出
-R, --root CHROOT_DIR chroot 到的目录
-S, --set set lastlog record to current time (usable only with -u)
-t, --time DAYS 仅打印晚于 DAYS 的最近登录记录
-u, --user LOGIN 打印 LOGIN 用户的最近登录记录
04. 参考示例
4.1 显示系统中所有用户最近一次登录信息
[root@itcast ~]# lastlog
4.2 显示指定天数前的登录信息
[root@itcast ~]# lastlog -b 7
4.3 显示指定天数以来的登录信息
[root@itcast ~]# lastlog -t 7
用户名 端口 来自 最后登陆时间
root pts/0 六 8月 3 10:27:37 +0800 2019
deng pts/0 172.16.0.51 六 8月 3 10:27:30 +0800 2019
itcast pts/1 三 7月 31 21:25:50 +0800 2019
[root@itcast ~]#
4.4 显示指定用户的最近登录信息
[root@itcast ~]# lastlog -u root
用户名 端口 来自 最后登陆时间
root pts/0 六 8月 3 10:27:37 +0800 2019
[root@itcast ~]#
4.5 清除指定用户的登录信息
[root@itcast ~]# lastlog -C -u root
[root@itcast ~]#
[root@itcast ~]#
[root@itcast ~]# lastlog -u root
用户名 端口 来自 最后登陆时间
root **从未登录过**
[root@itcast ~]#