Linux命令完全指南

Linux lastlog命令使用详解

lastlog命令用于报告所有用户的最近登录情况,或者指定用户的最近登录情况。

lastlog文件在每次有用户登录时被查询。可以使用lastlog命令检查某特定用户上次登录的时间,并格式化输出上次登录日志/var/log/lastlog的内容。它根据UID排序显示登录名、端口号(tty)和上次登录时间。如果一个用户从未登录过,lastlog显示**Never logged**。注意需要以root身份运行该命令。

语法

1
lastlog [选项]

选项

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
-b, --beforeDAYS
只显示老于 DAYS 的最近登录记录。

-C, --clear
Clear lastlog record of an user. This option can be used only
together with -u (--user)).

-h, --help
现实帮助信息并退出。

-R, --rootCHROOT_DIR
Apply changes in the CHROOT_DIR directory and use the configuration
files from the CHROOT_DIR directory.

-S, --set
Set lastlog record of an user to the current time. This option can
be used only together with -u (--user)).

-t, --timeDAYS
只现实新于 DAYS 的最近登录记录。

-u, --userLOGIN|RANGE
现实指定用户的最近登录记录。

The users can be specified by a login name, a numerical user ID, or
a RANGE of users. This RANGE of users can be specified with a min
and max values (UID_MIN-UID_MAX), a max value (-UID_MAX), or a min
value (UID_MIN-).

如果用户从来没有登录过,将会显示 ** 从未登录 ** 而不是端口和时间。

实例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
用户名           端口     来自             最后登陆时间
root pts/0 192.168.111.1 六 5月 18 15:23:20 +0800 2016
bin **从未登录过**
daemon **从未登录过**
adm **从未登录过**
lp **从未登录过**
sync **从未登录过**
shutdown **从未登录过**
halt **从未登录过**
mail **从未登录过**
operator **从未登录过**
games **从未登录过**
ftp **从未登录过**
nobody **从未登录过**
systemd-network **从未登录过**
dbus **从未登录过**
polkitd **从未登录过**
tss **从未登录过**
sshd **从未登录过**
postfix **从未登录过**
chrony **从未登录过**
apache **从未登录过**