一聚教程网:一个值得你收藏的教程网站

热门教程

Linux系统之last命令的基本使用

时间:2026-08-13 11:17:50 编辑:袖梨 来源:一聚教程网

在这里插入图片描述

一、last命令介绍

二、last命令的使用帮助

2.1 last命令help帮助信息

[root@openEuler-test ~]# last --helpUsage: last [options] [<username>...] [<tty>...]Show a listing of last logged in users.Options: -<number>how many lines to show -a, --hostlast display hostnames in the last column -d, --dnstranslate the IP number back into a hostname -f, --file <file>use a specific file instead of /var/log/wtmp -F, --fulltimesprint full login and logout times and dates -i, --ip display IP numbers in numbers-and-dots notation -n, --limit <number> how many lines to show -R, --nohostname don't display the hostname field -s, --since <time> display the lines since the specified time -t, --until <time> display the lines until the specified time -p, --present <time> display who were present at the specified time -w, --fullnamesdisplay full user and domain names -x, --system display system shutdown entries and run level changes --time-format <format>show timestamps in the specified <format>: notime|short|full|iso -h, --help display this help -V, --versiondisplay versionFor more details see last(1).

2.2 last命令选项解释

last [选项] [<用户名>...] [<终端>...]
选项
选项描述
-显示多少行记录
-a, --hostlast在最后一列中显示主机名
-d, --dns将IP地址转换回主机名
-f, --file <文件>使用指定的文件而不是 /var/log/wtmp
-F, --fulltimes打印完整的登录和登出时间和日期
-i, --ip以点分十进制格式显示IP地址
-n, --limit <数量>显示多少行记录
-R, --nohostname不显示主机名字段
-s, --since <时间>显示从指定时间开始的记录
-t, --until <时间>显示到指定时间为止的记录
-p, --present <时间>显示在指定时间时在线的用户
-w, --fullnames显示完整的用户名和域名
-x, --system显示系统关机条目和运行级别变更
--time-format <格式>按照指定的 <格式> 显示时间戳:notimeshortfulliso
-h, --help显示此帮助
-V, --version显示版本号

三、last命令的基本使用

3.1 last直接使用

[root@openEuler-test ~]# lastroot pts/0192.168.3.241Sat Sep 28 11:58 still logged inroot pts/0192.168.3.241Fri Sep 27 13:27 - 14:02(00:34)reboot system boot6.6.0-28.0.0.34. Fri Sep 27 13:26 still runningroot pts/0192.168.3.241Fri Sep 27 11:16 - down (02:09)root pts/0192.168.3.241Fri Sep 27 08:49 - 09:19(00:29)root pts/0192.168.3.241Thu Sep 26 14:06 - 15:29(01:23)root pts/0192.168.3.241Thu Sep 26 13:32 - 14:05(00:32)root pts/0192.168.3.241Wed Sep 25 18:54 - 01:09(06:15)root pts/1192.168.3.241Tue Sep 24 23:06 - 00:14(01:07)root pts/0192.168.3.241Tue Sep 24 22:59 - 00:14(01:15)root pts/0192.168.3.241Tue Sep 24 22:47 - 22:58(00:10)root pts/0192.168.3.241Tue Sep 24 22:41 - 22:45(00:03)root pts/0192.168.3.241Tue Sep 24 22:39 - 22:39(00:00)root pts/0192.168.3.241Tue Sep 24 11:15 - 13:52(02:36)root pts/0192.168.3.241Sun Sep 22 23:52 - 01:01(01:08)root pts/0192.168.3.241Sat Sep7 14:57 - 00:59(10:02)reboot system boot6.6.0-28.0.0.34. Sun Sep1 04:40 - 13:26 (26 08:46)root pts/0192.168.3.241Sun Sep1 04:33 - down (00:06)root pts/0192.168.3.241Thu Aug 29 03:05 - 10:05(07:00)root pts/0192.168.3.241Wed Aug 21 07:19 - 20:04(12:44)root pts/0192.168.3.241Mon Aug 19 13:09 - 14:43(01:33)root pts/0192.168.3.241Wed Aug 14 20:43 - 20:43(00:00)root pts/0192.168.3.241Tue Aug 13 19:43 - 04:46(09:03)root pts/0192.168.3.241Mon Aug 12 11:12 - 03:19(16:07)root pts/0192.168.3.241Sun Aug 11 21:26 - 00:12(02:46)root pts/0192.168.3.241Sun Aug 11 10:02 - 10:19(00:17)root pts/0192.168.3.241Sat Aug 10 12:02 - 21:42(09:40)root pts/1192.168.3.241Thu Aug8 16:46 - 19:00(02:14)root pts/0192.168.3.168Thu Aug8 16:41 - 18:55(02:14)root tty1Thu Aug8 16:40 - 04:39 (23 11:59)reboot system boot6.6.0-28.0.0.34. Thu Aug8 16:38 - 04:39 (23 12:01)reboot system boot6.6.0-28.0.0.34. Thu Jun 27 15:54 - 04:39 (65 12:45)wtmp begins Thu Jun 27 15:54:01 2024

3.2 显示特定用户的登录记录

[root@openEuler-test ~]# last adminadminpts/1192.168.3.89 Sat Sep 28 15:55 - 15:55(00:00)wtmp begins Thu Jun 27 15:54:01 2024

3.3 显示自系统启动以来的所有活动

[root@openEuler-test ~]# last rebootreboot system boot6.6.0-28.0.0.34. Fri Sep 27 13:26 still runningreboot system boot6.6.0-28.0.0.34. Sun Sep1 04:40 - 13:26 (26 08:46)reboot system boot6.6.0-28.0.0.34. Thu Aug8 16:38 - 04:39 (23 12:01)reboot system boot6.6.0-28.0.0.34. Thu Jun 27 15:54 - 04:39 (65 12:45)wtmp begins Thu Jun 27 15:54:01 2024

3.4 显示指定数量的最新记录

[root@openEuler-test ~]# last -n 5adminpts/1192.168.3.89 Sat Sep 28 15:55 - 15:55(00:00)root pts/0192.168.3.241Sat Sep 28 11:58 still logged inroot pts/0192.168.3.241Fri Sep 27 13:27 - 14:02(00:34)reboot system boot6.6.0-28.0.0.34. Fri Sep 27 13:26 still runningroot pts/0192.168.3.241Fri Sep 27 11:16 - down (02:09)wtmp begins Thu Jun 27 15:54:01 2024

3.5 查询1小时前还在线用户

[root@openEuler-test ~]# last -p "1 hour ago"root pts/0192.168.3.241Sat Sep 28 11:58 still logged inreboot system boot6.6.0-28.0.0.34. Fri Sep 27 13:26 still runningwtmp begins Thu Jun 27 15:54:01 2024

四、总结

热门栏目