LOADING...

加载中请稍等...

loading

Linux每日一篇 - 83 - last

Linux登录历史查看神器!掌握last命令,轻松查看用户登录历史,了解系统使用记录!

last命令是什么?

last命令用于显示用户登录历史记录,从系统的wtmp文件中读取信息,显示用户登录、注销、系统启动和关闭的时间记录,是审计系统使用情况的重要工具。

基本用法

# 显示所有用户登录历史
last

# 显示指定用户的登录历史
last username

# 显示最近10次登录记录
last | head -10

# 显示指定用户的最近几次登录
last -n 5 username

# 显示特定时间段的登录记录
last -s yesterday

# 显示从特定时间开始的登录记录
last -s "2026-01-01"

# 显示到特定时间的登录记录
last -t "2026-01-31"

# 显示特定终端的登录记录
last -t tty1

实用技巧

# 查看当前用户的登录历史
last $USER

# 查看最近的系统重启记录
last reboot

# 查看当前用户的最近5次登录
last -n 5 $USER

# 统计登录次数
last $USER | grep "$USER" | wc -l

# 查看最近一周的登录记录
last -s "7 days ago"

# 查看今天的所有登录记录
last -s today

# 统计特定用户登录次数
last username | grep "username" | wc -l

# 查看登录时长(需要额外计算)
last -F

# 查看失败登录尝试(如果配置了相关日志)
lastb

常用场景

# 查看系统登录历史
last

# 检查当前用户的登录记录
last $(whoami)

# 查看特定用户登录情况
last username

# 检查系统重启历史
last reboot

# 查看今天的登录活动
last -s today

# 统计用户的登录频率
last username | head -20

# 查看系统最近的使用情况
last | head -15

# 检查是否有异常登录记录
last | grep -v "reboot\|shutdown\|system boot"

# 分析登录模式
last -s "7 days ago" | head -20
头像
汪多多是只猫
失业的运维工程师
热爱开源与分享
微信公众号