wtmp 文件是一个struct utmp记录序列。要删除最后 10 条记录,首先要找出 utmp 记录的大小,然后将 wtmp 文件截断为其当前大小减去 utmp 记录大小的 10 倍。
一个简单的 C 程序将为您提供 utmp 记录的大小。
#include <utmp.h>
#include <stdio.h>
struct utmp foo;
main()
{
printf("%lu\n", sizeof foo);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
Perl 脚本将截断 wtmp 文件
$utmp_size = utmp_record_size_goes_here;
$wtmp_file = "wtmp filename goes here";
open WTMP, "+<", $wtmp_file or die "$wtmp_file: ", $!;
seek WTMP, -10 * $utmp_size, 2;
truncate WTMP, tell(WTMP);
close WTMP;
Run Code Online (Sandbox Code Playgroud)