Linux常用命令last的使用方法详解

 更新时间:2017年08月02日 10:07:28   作者:潇湘隐者  
最近在学习linux命令,学习到了last命令,发现很多同学对last命令不是很熟悉,last命令的功能列出目前与过去登入系统的用户相关信息,下面这篇文章主要给大家介绍了关于Linux常用命令last的使用方法,需要的朋友可以参考借鉴。

前言

本文主要给大家介绍了关于Linux常用命令last用法的相关内容,分享出来供大家参考学习,话不多说,来一起看看详细的介绍吧。

命令简介:

该命令用来列出目前与过去登录系统的用户相关信息。指令英文原义:show listing of last logged in users

执行权限 :有些需要特殊权限

指令所在路径:/usr/bin/last

执行last指令时,它会读取位于/var/log目录下名称为wtmp的文件,并把该给文件的内容记录的登录系统的用户名单全部显示出来。默认是显示wtmp的记录,btmp能显示的更详细,可以显示远程登录,例如ssh登录。

utmp文件中保存的是当前正在本系统中的用户的信息。

wtmp文件中保存的是登录过本系统的用户的信息。

命令输出字段介绍:

   第一列:用户名

   第二列:终端位置。pts/0 (伪终端) 意味着从诸如SSH或telnet的远程连接的用户.tty (teletypewriter) 意味着直接连接到计算机或者本地连接的用户

   第三列:登录ip或者内核 。如果你看见:0.0 或者什么都没有,这意味着用户通过本地终端连接。除了重启活动,内核版本会显示在状态中。

   第四列:开始时间

   第五列:结束时间(still login in 还未退出 down 直到正常关机 crash 直到强制关机)

   第六列:持续时间

命令语法:

last [-R] [-num] [ -n num ] [-adiowx] [ -f file ] [ -t YYYYMMDDHHMMSS ] [name...]  [tty...]

命令参数:

参数

长参数

描叙

-a

将登录系统的的主机名称或IP地址,显示在最后一行

-d

将IP地址转换成主机名称

-f

指定记录文件,默认是显示/var/log目录下的wtmp文件的记录,但/var/log目录下得btmp能显示的内容更丰富,可以显示远程登录,例如ssh登录 ,包括失败的登录请求。

-i

-i显示特定ip登录的情况。跟踪用 -i显示特定ip登录的情况。跟踪用

-o

Read an old-type wtmp file (written by linux-libc5 applications).

-n

-n <显示行数>或-<显示行数>  设置显示多少行记录

-w

Display full user and domain names in the output

-R

不显示登入系统的主机名称或IP(省略 hostname 的栏位)

-t

显示YYYYMMDDHHMMSS之前的信息

-x

显示系统关闭、用户登录和退出的历史

使用示例:

1:查看last命令的帮助信息

[root@DB-Server ~]# man last
 
 
 
[root@DB-Server ~]# last -h
last: invalid option -- h
Usage: last [-num | -n num] [-f file] [-t YYYYMMDDHHMMSS] [-R] [-x] [-o] [-w] [username..] [tty..]

2:显示最后登录系统的N条记录

[root@DB-Server ~]#last -10
root pts/1 :0.0 Wed Dec 18 09:54 still logged in 
root pts/4 :0.0 Wed Dec 18 09:43 - 09:48 (00:04) 
root pts/1 :0.0 Wed Dec 18 09:43 - 09:48 (00:05) 
root pts/3 192.168.103.79 Wed Dec 18 09:41 - 12:40 (02:59) 
root pts/4 :0.0 Wed Dec 18 09:28 - 09:30 (00:01) 
root pts/3 :0.0 Wed Dec 18 09:27 - 09:30 (00:02) 
root pts/2 192.168.103.29 Wed Dec 18 09:27 still logged in 
root pts/1 :0.0 Wed Dec 18 09:27 - 09:42 (00:15) 
root pts/2 :0.0 Wed Dec 18 09:23 - 09:25 (00:01) 
root pts/1 :0.0 Wed Dec 18 09:22 - 09:25 (00:02) 
 
wtmp begins Wed Dec 11 03:02:17 2013
 
[root@DB-Server ~]# last -n 10
root pts/1 :0.0 Wed Dec 18 09:54 still logged in 
root pts/4 :0.0 Wed Dec 18 09:43 - 09:48 (00:04) 
root pts/1 :0.0 Wed Dec 18 09:43 - 09:48 (00:05) 
root pts/3 192.168.103.79 Wed Dec 18 09:41 - 12:40 (02:59) 
root pts/4 :0.0 Wed Dec 18 09:28 - 09:30 (00:01) 
root pts/3 :0.0 Wed Dec 18 09:27 - 09:30 (00:02) 
root pts/2 192.168.103.29 Wed Dec 18 09:27 still logged in 
root pts/1 :0.0 Wed Dec 18 09:27 - 09:42 (00:15) 
root pts/2 :0.0 Wed Dec 18 09:23 - 09:25 (00:01) 
root pts/1 :0.0 Wed Dec 18 09:22 - 09:25 (00:02) 
 
wtmp begins Wed Dec 11 03:02:17 2013

3:将登录系统的主机名或IP地址显示在最后一行

[root@DB-Server ~]# last -10 -a
root pts/1 Wed Dec 18 09:54 still logged in :0.0
root pts/4 Wed Dec 18 09:43 - 09:48 (00:04) :0.0
root pts/1 Wed Dec 18 09:43 - 09:48 (00:05) :0.0
root pts/3 Wed Dec 18 09:41 - 12:40 (02:59) 192.168.103.79
root pts/4 Wed Dec 18 09:28 - 09:30 (00:01) :0.0
root pts/3 Wed Dec 18 09:27 - 09:30 (00:02) :0.0
root pts/2 Wed Dec 18 09:27 still logged in 192.168.103.29
root pts/1 Wed Dec 18 09:27 - 09:42 (00:15) :0.0
root pts/2 Wed Dec 18 09:23 - 09:25 (00:01) :0.0
root pts/1 Wed Dec 18 09:22 - 09:25 (00:02) :0.0
 
wtmp begins Wed Dec 11 03:02:17 2013

4:不显示登入系统的主机名称或IP地址

[root@DB-Server ~]# last -10 -R
root pts/1 Wed Dec 18 09:54 still logged in 
root pts/4 Wed Dec 18 09:43 - 09:48 (00:04) 
root pts/1 Wed Dec 18 09:43 - 09:48 (00:05) 
root pts/3 Wed Dec 18 09:41 - 12:40 (02:59) 
root pts/4 Wed Dec 18 09:28 - 09:30 (00:01) 
root pts/3 Wed Dec 18 09:27 - 09:30 (00:02) 
root pts/2 Wed Dec 18 09:27 still logged in 
root pts/1 Wed Dec 18 09:27 - 09:42 (00:15) 
root pts/2 Wed Dec 18 09:23 - 09:25 (00:01) 
root pts/1 Wed Dec 18 09:22 - 09:25 (00:02) 
 
wtmp begins Wed Dec 11 03:02:17 2013

5: 指定/var/log/btmp文件,查看登录系统的用户相关信息

[root@DB-Server ~]# last -n 10 -f /var/log/btmp
root ssh:notty 192.168.136.163 Fri Oct 17 18:16 gone - no logout 
root ssh:notty 192.168.136.163 Fri Oct 17 09:50 - 18:16 (08:26) 
root ssh:notty 192.168.136.163 Fri Oct 17 09:50 - 09:50 (00:00) 
root ssh:notty 192.168.40.218 Tue Jul 23 17:40 - 09:50 (450+16:10) 
root ssh:notty 192.168.236.149 Sun Apr 14 01:34 - 17:40 (100+16:05) 
root ssh:notty 192.168.178.147 Fri Mar 8 17:25 - 01:34 (36+08:08) 
tomcat ssh:notty get185806.gfg1.e Fri Oct 26 16:48 - 17:25 (133+00:37) 
root ssh:notty 192.168.193.3 Mon Oct 22 18:13 - 16:48 (3+22:34) 
root ssh:notty 192.168.193.3 Mon Oct 22 18:13 - 18:13 (00:00) 
devloper ssh:notty get185819.gfg1.e Wed Oct 17 17:22 - 18:13 (5+00:50) 
 
btmp begins Thu Apr 12 14:30:06 2012

6: 将IP地址转换成主机名称

last -10 -d 

7: 显示YYYYMMDDHHMMSS(20150110093000)之前的信息

[root@DB-Server ~]# last -10 -t 20150110093000
root pts/2 192.168.102.186 Fri Jan 9 15:35 - 17:27 (01:52) 
root pts/2 192.168.102.134 Thu Jan 8 10:25 - 12:27 (02:02) 
root pts/3 192.168.125.53 Tue Jan 6 23:59 - 00:09 (00:09) 
root pts/2 192.168.125.53 Tue Jan 6 23:45 - 00:09 (00:23) 
root pts/3 192.168.102.88 Tue Jan 6 15:23 - 16:20 (00:57) 
root pts/2 192.168.102.88 Tue Jan 6 15:08 - 17:25 (02:16) 
oracle pts/1 :2.0 Tue Jan 6 15:07 still logged in 
reboot system boot 2.6.32-200.13.1. Tue Jan 6 15:07 (7+20:21) 
root pts/2 192.168.102.88 Tue Jan 6 14:47 - down (00:17) 
oracle pts/1 :2.0 Tue Jan 6 14:46 - down (00:18) 
 
wtmp begins Wed Apr 11 16:31:10 2012

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对脚本之家的支持。

相关文章

  • 在Linux中安装Git的详细流程

    在Linux中安装Git的详细流程

    本文介绍在Linux操作系统的Ubuntu版本中,配置分布式开源版本控制系统Git,随后基于Git克隆GitHub中项目的代码的详细方法,需要的朋友可以参考下
    2024-04-04
  • 禁止网站显示文件目录列表的2个方法(htaccess)

    禁止网站显示文件目录列表的2个方法(htaccess)

    这篇文章主要介绍了禁止网站显示文件目录列表的2个方法,需要的朋友可以参考下
    2016-04-04
  • Linux流媒体服务器部署流程

    Linux流媒体服务器部署流程

    文章详细介绍了流媒体服务器的部署步骤,包括更新系统、安装依赖组件、编译安装Nginx和RTMP模块、配置Nginx和FFmpeg,以及测试流媒体服务器的搭建
    2025-02-02
  • CentOS基于nginx反向代理实现负载均衡的方法

    CentOS基于nginx反向代理实现负载均衡的方法

    这篇文章主要介绍了CentOS基于nginx反向代理实现负载均衡的方法,简单分析了CentOS环境下nginx负载均衡的原理及nginx安装与相关设置操作技巧,需要的朋友可以参考下
    2018-04-04
  • Git 删除远程服务器文件同时保留本地文件实例详解

    Git 删除远程服务器文件同时保留本地文件实例详解

    这篇文章主要介绍了Git 删除远程服务器文件同时保留本地文件实例详解的相关资料,需要的朋友可以参考下
    2017-05-05
  • Apache Omid TSO 组件源码实现原理解析

    Apache Omid TSO 组件源码实现原理解析

    这篇文章主要介绍了Apache Omid TSO 组件源码实现原理解析,本文给大家介绍的非常详细,感兴趣的朋友一起看看吧
    2024-07-07
  • Linux文件删除后空间未释放问题详解

    Linux文件删除后空间未释放问题详解

    这篇文章主要给大家介绍了关于Linux文件删除后空间未释放问题的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用Linux具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
    2020-05-05
  • Centos 6.5 下配置DNS服务器的方法(图文详解)

    Centos 6.5 下配置DNS服务器的方法(图文详解)

    这篇文章主要介绍了Centos 6.5 下配置DNS服务器的方法详解,需要的朋友可以参考下
    2017-05-05
  • linux中rmdir命令使用详解

    linux中rmdir命令使用详解

    这篇文章主要详细介绍了linux中rmdir命令使用方法以及示例,十分的全面,这里推荐给想学习linux命令的小伙伴
    2015-01-01
  • linux epoll机制详解

    linux epoll机制详解

    这篇文章主要介绍了linux epoll机制详解,介绍了select()和poll() IO多路复用模型,epoll IO多路复用模型实现机制,epoll的接口和工作模式等相关内容,小编觉得还是挺不错的,这里分享给大家,需要的朋友可以参考下
    2018-01-01

最新评论