功能说明:列出目前与过去登入系统的用户相关信息。
语 法:last [-adRx][-f <记录文件>][-n <显示行数>][帐号名称...][终端机编号...]
补充说明:单独执行last指令,它会读取位于/var/log目录下,名称为wtmp的文件,并把该给文件的内容记录的登入系统的用户名单全部显示出来。
参 数:
-a 把从何处登入系统的主机名称或IP地址,显示在最后一行。
-d 将IP地址转换成主机名称。
-f <记录文件> 指定记录文件。
-n <显示行数>或-<显示行数> 设置列出名单的显示行数。
-R 不显示登入系统的主机名称或IP地址。
-x 显示系统关机,重新开机,以及执行等级的改变等信息。
例子:
[root@ora2 ~]# date
Tue May 10 21:14:52 CST 2011
[root@ora2 ~]# last -a
root pts/3 Tue May 10 21:14 still logged in 192.168.36.71
root pts/2 Tue May 10 21:09 still logged in :0.0
root pts/1 Tue May 10 21:05 still logged in :0.0
root :0 Tue May 10 21:04 still logged in
root :0 Tue May 10 21:04 - 21:04 (00:00)
reboot system boot Tue May 10 20:57 (00:17) 2.6.18-92.el5
root pts/2 Wed Jan 26 05:36 - crash (104+15:21) 192.168.36.71
root pts/1 Wed Jan 26 05:35 - crash (104+15:22) :0.0
root :0 Wed Jan 26 05:34 - crash (104+15:23)
root :0 Wed Jan 26 05:34 - 05:34 (00:00)
reboot system boot Wed Jan 26 05:07 (104+16:07) 2.6.18-92.el5
reboot system boot Wed Jan 26 04:47 (00:16) 2.6.18-92.el5
wtmp begins Wed Jan 26 04:47:12 2011
[root@ora2 ~]# last
root pts/3 192.168.36.71 Tue May 10 21:14 still logged in
root pts/2 :0.0 Tue May 10 21:09 still logged in
root pts/1 :0.0 Tue May 10 21:05 still logged in
root :0 Tue May 10 21:04 still logged in
root :0 Tue May 10 21:04 - 21:04 (00:00)
reboot system boot 2.6.18-92.el5 Tue May 10 20:57 (00:17)
root pts/2 192.168.36.71 Wed Jan 26 05:36 - crash (104+15:21)
root pts/1 :0.0 Wed Jan 26 05:35 - crash (104+15:22)
root :0 Wed Jan 26 05:34 - crash (104+15:23)
root :0 Wed Jan 26 05:34 - 05:34 (00:00)
reboot system boot 2.6.18-92.el5 Wed Jan 26 05:07 (104+16:07)
reboot system boot 2.6.18-92.el5 Wed Jan 26 04:47 (00:16)
wtmp begins Wed Jan 26 04:47:12 2011
[root@ora2 ~]# last -d
root pts/3 192.168.36.71 Tue May 10 21:14 still logged in
root pts/2 :0.0 Tue May 10 21:09 still logged in
root pts/1 :0.0 Tue May 10 21:05 still logged in
root :0 Tue May 10 21:04 still logged in
root :0 Tue May 10 21:04 - 21:04 (00:00)
reboot system boot 2.6.18-92.el5 Tue May 10 20:57 (00:17)
root pts/2 192.168.36.71 Wed Jan 26 05:36 - crash (104+15:21)
root pts/1 :0.0 Wed Jan 26 05:35 - crash (104+15:22)
root :0 Wed Jan 26 05:34 - crash (104+15:23)
root :0 Wed Jan 26 05:34 - 05:34 (00:00)
reboot system boot 2.6.18-92.el5 Wed Jan 26 05:07 (104+16:08)
reboot system boot 2.6.18-92.el5 Wed Jan 26 04:47 (00:16)
wtmp begins Wed Jan 26 04:47:12 2011
[root@ora2 ~]# man last
Formatting page, please wait...
LAST,LASTB(1) Linux System Administrator鈥檚 Manual LAST,LASTB(1)
NAME
last, lastb - show listing of last logged in users
SYNOPSIS
last [-R] [-num] [ -n num ] [-adiox] [ -f file ] [ -t YYYYMMDDHHMMSS ]
[name...] [tty...]
lastb [-R] [-num] [ -n num ] [ -f file ] [-adiox] [name...] [tty...]
DESCRIPTION
Last searches back through the file /var/log/wtmp (or the file desig-
nated by the -f flag) and displays a list of all users logged in (and
out) since that file was created. Names of users and tty鈥檚 can be
given, in which case last will show only those entries matching the
arguments. Names of ttys can be abbreviated, thus last 0 is the same
as last tty0.
When last catches a SIGINT signal (generated by the interrupt key, usu-
ally control-C) or a SIGQUIT signal (generated by the quit key, usually
control-/), last will show how far it has searched through the file; in
the case of the SIGINT signal last will then terminate.
The pseudo user reboot logs in each time the system is rebooted. Thus
last reboot will show a log of all reboots since the log file was cre-
ated.
Lastb is the same as last, except that by default it shows a log of the
file /var/log/btmp, which contains all the bad login attempts.
OPTIONS
-num This is a count telling last how many lines to show.
-n num The same.
-t YYYYMMDDHHMMSS
Display the state of logins as of the specified time. This is
useful, e.g., to determine easily who was logged in at a partic-
ular time -- specify that time with -t and look for "still
logged in".
-f file
Specifies a file to search other than /var/log/wtmp.
-R Suppresses the display of the hostname field.
-a Display the hostname in the last column. Useful in combination
with the next flag.
-d For non-local logins, Linux stores not only the host name of the
remote host but its IP number as well. This option translates
the IP number back into a hostname.
-i This option is like -d in that it displays the IP number of the
remote host, but it displays the IP number in numbers-and-dots
notation.
-o Read an old-type wtmp file (written by linux-libc5 applica-
tions).
-x Display the system shutdown entries and run level changes.
NOTES
The files wtmp and btmp might not be found. The system only logs infor-
mation in these files if they are present. This is a local configura-
tion issue. If you want the files to be used, they can be created with
a simple touch(1) command (for example, touch /var/log/wtmp).
FILES
/var/log/wtmp
/var/log/btmp
AUTHOR
Miquel van Smoorenburg, [email protected]
SEE ALSO
shutdown(8), login(1), init(8)
Jul 31, 2004 LAST,LASTB(1)
[root@ora2 ~]# last
root pts/3 192.168.36.71 Tue May 10 21:14 still logged in
root pts/2 :0.0 Tue May 10 21:09 still logged in
root pts/1 :0.0 Tue May 10 21:05 still logged in
root :0 Tue May 10 21:04 still logged in
root :0 Tue May 10 21:04 - 21:04 (00:00)
reboot system boot 2.6.18-92.el5 Tue May 10 20:57 (00:18)
root pts/2 192.168.36.71 Wed Jan 26 05:36 - crash (104+15:21)
root pts/1 :0.0 Wed Jan 26 05:35 - crash (104+15:22)
root :0 Wed Jan 26 05:34 - crash (104+15:23)
root :0 Wed Jan 26 05:34 - 05:34 (00:00)
reboot system boot 2.6.18-92.el5 Wed Jan 26 05:07 (104+16:08)
reboot system boot 2.6.18-92.el5 Wed Jan 26 04:47 (00:16)
wtmp begins Wed Jan 26 04:47:12 2011
[root@ora2 ~]# last -R
root pts/3 Tue May 10 21:14 still logged in
root pts/2 Tue May 10 21:09 still logged in
root pts/1 Tue May 10 21:05 still logged in
root :0 Tue May 10 21:04 still logged in
root :0 Tue May 10 21:04 - 21:04 (00:00)
reboot system boot Tue May 10 20:57 (00:18)
root pts/2 Wed Jan 26 05:36 - crash (104+15:21)
root pts/1 Wed Jan 26 05:35 - crash (104+15:22)
root :0 Wed Jan 26 05:34 - crash (104+15:23)
root :0 Wed Jan 26 05:34 - 05:34 (00:00)
reboot system boot Wed Jan 26 05:07 (104+16:08)
reboot system boot Wed Jan 26 04:47 (00:16)
wtmp begins Wed Jan 26 04:47:12 2011
[root@ora2 ~]# last - x
wtmp begins Wed Jan 26 04:47:12 2011
[root@ora2 ~]# last -x
root pts/3 192.168.36.71 Tue May 10 21:14 still logged in
root pts/2 :0.0 Tue May 10 21:09 still logged in
root pts/1 :0.0 Tue May 10 21:05 still logged in
root :0 Tue May 10 21:04 still logged in
root :0 Tue May 10 21:04 - 21:04 (00:00)
runlevel (to lvl 5) 2.6.18-92.el5 Tue May 10 20:57 - 21:16 (00:18)
reboot system boot 2.6.18-92.el5 Tue May 10 20:57 (00:18)
root pts/2 192.168.36.71 Wed Jan 26 05:36 - crash (104+15:21)
root pts/1 :0.0 Wed Jan 26 05:35 - crash (104+15:22)
root :0 Wed Jan 26 05:34 - crash (104+15:23)
root :0 Wed Jan 26 05:34 - 05:34 (00:00)
runlevel (to lvl 5) 2.6.18-92.el5 Wed Jan 26 05:07 - 20:57 (104+15:50)
reboot system boot 2.6.18-92.el5 Wed Jan 26 05:07 (104+16:09)
shutdown system down 2.6.18-92.el5 Wed Jan 26 05:04 - 21:16 (104+16:11)
runlevel (to lvl 6) 2.6.18-92.el5 Wed Jan 26 05:03 - 05:04 (00:00)
runlevel (to lvl 5) 2.6.18-92.el5 Wed Jan 26 04:47 - 05:03 (00:16)
reboot system boot 2.6.18-92.el5 Wed Jan 26 04:47 (00:16)
wtmp begins Wed Jan 26 04:47:12 2011
[root@ora2 ~]# last -a
root pts/3 Tue May 10 21:14 still logged in 192.168.36.71
root pts/2 Tue May 10 21:09 still logged in :0.0
root pts/1 Tue May 10 21:05 still logged in :0.0
root :0 Tue May 10 21:04 still logged in
root :0 Tue May 10 21:04 - 21:04 (00:00)
reboot system boot Tue May 10 20:57 (00:19) 2.6.18-92.el5
root pts/2 Wed Jan 26 05:36 - crash (104+15:21) 192.168.36.71
root pts/1 Wed Jan 26 05:35 - crash (104+15:22) :0.0
root :0 Wed Jan 26 05:34 - crash (104+15:23)
root :0 Wed Jan 26 05:34 - 05:34 (00:00)
reboot system boot Wed Jan 26 05:07 (104+16:09) 2.6.18-92.el5
reboot system boot Wed Jan 26 04:47 (00:16) 2.6.18-92.el5
wtmp begins Wed Jan 26 04:47:12 2011
[root@ora2 ~]# exit
logout