在 Linux 系统中,last 命令用于查看用户最近的登录记录。
当不带参数直接运行 last 指令时,它会读取 /var/log/ 目录下的 wtmp 文件,并列出所有文件中记录的用户登录信息。
last [选项] [用户名...] [终端...]
常用参数说明:
选项:
用户名:
终端:
展示两行记录并隐藏主机名列:
# last -R -2 root pts/0 Thu Apr 28 18:06 still logged in root pts/0 Tue Apr 26 09:06 - 19:36 (10:30)wtmp begins Sun Apr 3 13:11:25 2025
同样效果的另一个示例:
~# last -R -2 root pts/0 Thu Apr 28 18:06 still logged in root pts/0 Tue Apr 26 09:06 - 19:36 (10:30)wtmp begins Sun Apr 3 13:11:2
5 2025
常规方式显示:
# last ... root pts/4 Thu May 13 17:25 still logged in
root pts/2 Thu May 13 17:23 - 17:25 (00:02)
root pts/1 Thu May 13 16:46 still logged in
...
简洁显示并设置输出条目数量:
# last -n 5 -R root pts/4 Thu May 13 17:25 still logged in
root pts/2 Thu May 13 17:23 - 17:25 (00:02)
root pts/1 Thu May 13 16:46 still logged in
root pts/7 Thu May 13 15:36 still logged in
root pts/9 Thu May 13 15:35 still logged inwtmp begins Thu May 13 18:55:40 2014
显示包含源 IP 地址的最后一列:
# last -n 5 -a -i root pts/4 Thu May 13 17:25 still logged in 192.168.1.10 root pts/2 Thu May 13 17:23 - 17:25 (00:02) 192.168.1.10 root pts/1 Thu May 13 16:46 still logged in 192.168.1.10 root pts/7 Thu May 13 15:36 still logged in 192.168.1.10 root pts/9 Thu May 13 15:35 still logged in 192.168.1.10wtmp begins Thu May 13 18:55:40 2014