---
title: "Linux 查询用户 w、who、last、lastlog"
author: "eksliang"
date: "2015-07-20T15:49:12Z"
tags: []
categories: ["研发管理"]
slug: "linux-w-who-last-lastlog"
draft: false
lastmod: "2015-07-20T15:49:12Z"
id: 2228782
url: "https://eksliang.iteye.com/blog/2228782"
---

## 一、【W】显示目前登入系统的用户信息

 

```
[root@Mast1 ~]# w
 23:42:41 up 40 min,  2 users,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    192.168.177.1    23:33   18.00s  0.05s  0.05s -bash
root     pts/1    mast2.com        23:42    0.00s  0.09s  0.05s w
```

输出解释

 

第一行

当前时间、系统启动到现在的时间、登录用户的数目，系统在最近1秒、5秒和15秒的平均负载；

例如上面：系统启动时间为23:42:41、已经启动了40分钟、有两个用户登录到了该系统

第二行

登录帐号、终端名称、远程主机名、登录时间、空闲时间、JCPU、PCPU、当前正在执行的命令；

 

## 二、【who】显示目前登入系统的用户信息

 

```
[root@Mast1 ~]# who
root     pts/0        2015-07-19 23:33 (192.168.177.1)
root     pts/1        2015-07-19 23:42 (mast2.com)
用户名   终端名称     时间（主机名）
```

 

 

## 三、【last】列出目前与过去登入系统的用户相关信息

 

```
#最常使用，查看最后登录系统的N条命令
[root@master01 ~]# last -5
root     pts/0        192.168.16.36    Mon Jul 20 15:02   still logged in   
root     pts/1        192.168.27.216   Mon Jul 20 11:27   still logged in   
root     pts/0        192.168.16.103   Mon Jul 20 09:25 - 14:03  (04:37)    
root     pts/0        192.168.16.36    Wed Jul 15 11:00 - 20:58  (09:57)    
root     pts/0        192.168.16.36    Tue Jul 14 11:25 - 18:01  (06:36)     
```

 命令输出字段介绍：

 

1. 第一列：用户名
2. 第二列：终端位置。pts/0 (伪终端) 意味着从诸如SSH或telnet的远程连接的用户.tty (teletypewriter) 意味着直接连接到计算机或者本地连接的用户
3. 第三列：登录ip或者内核 。如果你看见:0.0 或者什么都没有，这意味着用户通过本地终端连接。
4. 第四列：开始时间
5. 第五列：结束时间（still login in 还未退出、 down 直到正常关机、 crash 直到强制关机）
6. 第六列：持续时间

文章介绍：[http://www.cnblogs.com/kerrycode/p/4223751.html]()

 

## 四、【lastlog】列出所有用户最后登录信息，会把系统用户也列出来

现有文章介绍：http://www.cnblogs.com/qiyebao/p/4331078.html