【Linux】一步一步学Linux——lastlog命令(100)

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 ~]# 

05. 附录

参考:【Linux】一步一步学Linux系列教程汇总

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值