---
title: "我使用过的Linux命令之who - 查看当前登录用户"
author: "codingstandards"
date: "2011-04-08T20:55:52Z"
tags: [".net", "BBS", "ITeye", "Linux", "thread"]
categories: ["操作系统"]
slug: "linux-who"
draft: false
lastmod: "2011-04-08T20:56:25Z"
id: 993347
url: "https://codingstandards.iteye.com/blog/993347"
---

# 我使用过的Linux命令之who - 查看当前登录用户

本文链接：[http://codingstandards.iteye.com/blog/993347](/blog/993347)   （转载请注明出处）

## 用途说明

who命令用于显示谁登录了系统（show who is logged on），who am i与之相同。另外一个叫whoami的命令，只输出用户账号。而who或者who am i不仅显示账号，还显示终端文件名、时间、来源IP等。

 

## 常用方式

格式：who

格式：who am i

简单显示当前登录系统用户的信息，可以轻松的获取当前登录系统的用户列表，包含使用终端登录。

 

格式：who -a

格式：who -aH

显示所有用户的所有信息（The -a argument of the who command lists all available output for each user on your system.）

-H参数表明显示表头（显示列标题）。

 

## 使用示例

### 示例一

\[root@web186 root]# who  
root     pts/7        Apr  8 20:37 (124.15.246.23)  
\[root@web186 root]# who am i  
root     pts/7        Apr  8 20:37 (124.15.246.23)  
\[root@web186 root]# whoami  
root  
\[root@web186 root]# who -m  
root     pts/7        Apr  8 20:37 (124.15.246.23)  
\[root@web186 root]#

 

### 示例二

who -a或who -aH的输出信息，没有-H参数不输出表头。

USER   用户登陆  
LINE    用户登陆使用终端  
TIME   用户登陆时间  
LDIE    用户空闲时间，即至进行操作的时间  
PID     用户登陆shell的进程ID

\[root@web186 root]# who -aH  
NAME       LINE         TIME         IDLE          PID COMMENT  EXIT          
                        Sep 10 16:45                14 id=si    term=0 exit=0  
           system boot  Sep 10 16:45                             
           run-level 3  Sep 10 16:45                   last=S    
                        Sep 10 16:46              1591 id=l3    term=0 exit=0  
LOGIN      tty1         Feb 21 11:22              1655 id=1      
                        Oct 12 16:35              9003 id=2      
LOGIN      tty3         Jun 23 12:53             29564 id=3      
LOGIN      tty4         Sep 10 16:46              2388 id=4      
LOGIN      tty5         Sep 10 16:46              2389 id=5      
LOGIN      tty6         Sep 10 16:46              2390 id=6      
           pts/0        Sep 14 18:42              8133 id=ts/0  term=0 exit=0  
LOGIN      tty1         Sep 10 16:59              5904 id=1      
           pts/1        Jun 24 14:25             14472 id=ts/1  term=0 exit=0  
           pts/2        Dec 17 18:49             27017 id=ts/2  term=0 exit=0  
           pts/3        Dec 21 18:02             13020 id=ts/3  term=0 exit=0  
           pts/4        Sep 18 18:23             31627 id=ts/4  term=0 exit=0  
           pts/5        Feb 20 21:13             27026 id=ts/5  term=0 exit=0  
           pts/6        Jan 27 12:24             10937 id=ts/6  term=0 exit=0  
root     + pts/7        Apr  8 20:37   .         19799 (124.15.246.23)  
           pts/8        Mar 26 14:55              4534 id=ts/8  term=0 exit=0  
           pts/9        Mar 26 14:55              5837 id=ts/9  term=0 exit=0  
           pts/10       Nov 27 21:18              9543 id=s/10  term=0 exit=0  
           pts/11       Mar 26 14:55             10173 id=s/11  term=0 exit=0  
           pts/12       Mar 26 12:17             23761 id=s/12  term=0 exit=0  
LOGIN      tty3         May 28 10:55              2220 id=3      
LOGIN      tty2         Oct 12 16:35              9003 id=2      
           pts/13       Mar 26 14:55              1135 id=s/13  term=0 exit=0  
\[root@web186 root]# 

 

## 问题思考

## 相关资料

【1】Blinux linux who 当前登录系统用户（含终端）  
http://www.shocr.com/linux-who/  
【2】程序人生 Linux who am i  
http://www.programlife.net/linux-who-am-i.html  
【3】PHPChina 论坛 linux Who命令详细介绍  
http://bbs.phpchina.com/thread-94190-1-1.html

 

 

返回 [我使用过的Linux命令系列总目录](/blog/786653)