TranslateProject/published/201401/Linux who command – Displays who is on the system.md
wxy 1ee2fc7cbe renamed: 10 Lesser Known Useful Linux Commands- Part V.md -> 201401/10 Lesser Known Useful Linux Commands- Part V.md
renamed:    10 Useful Chaining Operators in Linux with Practical Examples.md -> 201401/10 Useful Chaining Operators in Linux with Practical Examples.md
	renamed:    10 basic examples of linux netstat command.md -> 201401/10 basic examples of linux netstat command.md
	renamed:    12 Advanced Commands For Linux Server Admins!.md -> 201401/12 Advanced Commands For Linux Server Admins!.md
	renamed:    14 New Linux Distros That Were Introduced In 2013.md -> 201401/14 New Linux Distros That Were Introduced In 2013.md
	renamed:    15 Basic MySQL Interview Questions for Database Administrators.md -> 201401/15 Basic MySQL Interview Questions for Database Administrators.md
	renamed:    "2013\357\274\232The Golden Year for Linux \342\200\223 10 Biggest Linux Achievements.md" -> "201401/2013\357\274\232The Golden Year for Linux \342\200\223 10 Biggest Linux Achievements.md"
	renamed:    2014--The year of the Linux car.md -> 201401/2014--The year of the Linux car.md
	renamed:    5 Things To Love And Hate About Ubuntu 13.10.md -> 201401/5 Things To Love And Hate About Ubuntu 13.10.md
	renamed:    8 Interesting Linux Tips And Tricks!.md -> 201401/8 Interesting Linux Tips And Tricks!.md
	renamed:    CentOS 6.5 desktop installation guide with screenshots.md -> 201401/CentOS 6.5 desktop installation guide with screenshots.md
	renamed:    "Command Line Basics \342\200\223 watch.md" -> "201401/Command Line Basics \342\200\223 watch.md"
	renamed:    Configure Your Browser To Use Tor On Ubuntu or Debian or Linux Mint.md -> 201401/Configure Your Browser To Use Tor On Ubuntu or Debian or Linux Mint.md
	renamed:    Daily Ubuntu Tips - Mount Partitions In Ubuntu From Your Desktop GUI.md -> 201401/Daily Ubuntu Tips - Mount Partitions In Ubuntu From Your Desktop GUI.md
	renamed:    "Daily Ubuntu Tips \342\200\223 Do Nothing When Laptop Lid Is Closed.md" -> "201401/Daily Ubuntu Tips \342\200\223 Do Nothing When Laptop Lid Is Closed.md"
	renamed:    "Daily Ubuntu Tips \342\200\224 Install VMware Workstation In Ubuntu.md" -> "201401/Daily Ubuntu Tips \342\200\224 Install VMware Workstation In Ubuntu.md"
	renamed:    "Daily Ubuntu Tips \342\200\224 Windows Disk Management Equivalent In Ubuntu.md" -> "201401/Daily Ubuntu Tips \342\200\224 Windows Disk Management Equivalent In Ubuntu.md"
	renamed:    "Gnu--toward the post-scarcity world \342\200\223 the Free Software Column.md" -> "201401/Gnu--toward the post-scarcity world \342\200\223 the Free Software Column.md"
	renamed:    How to Dual Boot Ubuntu and Windows Properly.md -> 201401/How to Dual Boot Ubuntu and Windows Properly.md
	renamed:    "How to Install and Configure UFW \342\200\223 An Un-complicated FireWall in Debian or Ubuntu.md" -> "201401/How to Install and Configure UFW \342\200\223 An Un-complicated FireWall in Debian or Ubuntu.md"
	renamed:    How to Upgrade to GNOME 3.10 in Ubuntu 13.10.md -> 201401/How to Upgrade to GNOME 3.10 in Ubuntu 13.10.md
	renamed:    How to install and configure Nagios on Linux.md -> 201401/How to install and configure Nagios on Linux.md
	renamed:    How to set password policy on Linux.md -> 201401/How to set password policy on Linux.md
	renamed:    How to stitch photos together on Linux.md -> 201401/How to stitch photos together on Linux.md
	renamed:    How to upgrade MySQL server on Debian or Ubuntu.md -> 201401/How to upgrade MySQL server on Debian or Ubuntu.md
	renamed:    Juju ice-cream icon design.md -> 201401/Juju ice-cream icon design.md
	renamed:    Linus Torvalds Releases Last Linux Kernel 3.13 RC for 2013.md -> 201401/Linus Torvalds Releases Last Linux Kernel 3.13 RC for 2013.md
	renamed:    Linus Torvalds Says All Contributor License Agreements Are Broken.md -> 201401/Linus Torvalds Says All Contributor License Agreements Are Broken.md
	renamed:    Linux free Command - Display Free and used Memory in the System.md -> 201401/Linux free Command - Display Free and used Memory in the System.md
	renamed:    Linux id Command - Print user ID and group ID information.md -> 201401/Linux id Command - Print user ID and group ID information.md
	renamed:    Linux is Everywhere. We show you exactly where.md -> 201401/Linux is Everywhere. We show you exactly where.md
	renamed:    Linux lsusb Command to Print information about USB on System.md -> 201401/Linux lsusb Command to Print information about USB on System.md
	renamed:    Linux vmstat Command - Tool to Report Virtual Memory Statistics.md -> 201401/Linux vmstat Command - Tool to Report Virtual Memory Statistics.md
	renamed:    "Linux who command \342\200\223 Displays who is on the system.md" -> "201401/Linux who command \342\200\223 Displays who is on the system.md"
	renamed:    "Move Dropbox\342\200\231s Folder To An External Drive In Ubuntu.md" -> "201401/Move Dropbox\342\200\231s Folder To An External Drive In Ubuntu.md"
	renamed:    New Ubuntu 14.04 Icons Are Drop-Dead Gorgeous, Might Not Arrive in Desktop Version.md -> 201401/New Ubuntu 14.04 Icons Are Drop-Dead Gorgeous, Might Not Arrive in Desktop Version.md
	renamed:    Our Top 10 Linux Applications of 2013.md -> 201401/Our Top 10 Linux Applications of 2013.md
	renamed:    Setup your personal Cloud server in minutes using ownCloud On RHEL, CentOS, Scientific Linux 6.5.md -> 201401/Setup your personal Cloud server in minutes using ownCloud On RHEL, CentOS, Scientific Linux 6.5.md
	renamed:    Software May Be Eating The World, But Open Source Software Is Eating Itself.md -> 201401/Software May Be Eating The World, But Open Source Software Is Eating Itself.md
	renamed:    The Debian Administrator's Handbook updated for Debian 7 Wheezy published and freely available for download.md -> 201401/The Debian Administrator's Handbook updated for Debian 7 Wheezy published and freely available for download.md
	renamed:    The Fedora Project Will No Longer Name Its Linux Distributions.md -> 201401/The Fedora Project Will No Longer Name Its Linux Distributions.md
	renamed:    The Genius Of Linux Is Community, Not Technology.md -> 201401/The Genius Of Linux Is Community, Not Technology.md
	renamed:    Top 10 Linux Distros For Hackers!.md -> 201401/Top 10 Linux Distros For Hackers!.md
	renamed:    Tunnel SSH Connections Over SSL Using 'Stunnel' On Debian 7  Ubuntu 13.10.md -> 201401/Tunnel SSH Connections Over SSL Using 'Stunnel' On Debian 7  Ubuntu 13.10.md
	renamed:    Ubuntu Stores Your Wi-Fi Passwords By Default!.md -> 201401/Ubuntu Stores Your Wi-Fi Passwords By Default!.md
	renamed:    Ubuntu Will Reach True Convergence Before Microsoft, Says Shuttleworth.md -> 201401/Ubuntu Will Reach True Convergence Before Microsoft, Says Shuttleworth.md
	renamed:    Understanding Linux cd Command with Examples.md -> 201401/Understanding Linux cd Command with Examples.md
	renamed:    look--Linux Command To Verify Spellings And Display Lines Beginning With A String.md -> 201401/look--Linux Command To Verify Spellings And Display Lines Beginning With A String.md
2014-02-03 20:55:51 +08:00

4.0 KiB
Raw Blame History

Linux who 命令 显示系统登录者

作为一名系统管理员我们需要弄清楚在一个特定的时间点都有谁活跃在系统上。必须严密监视我们的服务器。但是我们当然不可能一天24小时都盯着系统。在linux系统中我们可以使用who命令查看登录者信息。

什么是 who 命令

who命令能够打印 当前都有谁登录到系统中 的相关信息 。who命令只会显示真正登录到系统中的用户。它不会显示那些通过su命令切换用户的登录者。

如何使用who命令

在大多数linux发行版中who命令都是默认安装上的。想使用该命令只需在控制台敲命令就行了。不带选项的话运行该命令产生默认输出。

$ who

如何理解输出:

  • 第一列显示用户名称
  • 第二列显示用户连接方式。Tty意味着用户直接连接到电脑上而pts意味着远程登录。
  • 第三、四列分别显示日期和时间
  • 第五列显示用户登录IP地址。

使用带参数的who命令

Who命令有一些参数用于调整输出。以下是常用的例子。

显示上一次重新启动的时间和日期

使用 -b 选项

$ who -b

可以看到系统启动是在2013年12月21日下午3:52。

显示初始化进程的当前运行级别

使用 -r 选项who命令会打印出初始化进程的当前运行级别

$ who -r

输出显示2013年12月21日下午3:52系统以 级别2 开始运行。

为每一列添加标题

使用 -H 选项为每一列添加标题

$ who -H

只打印当前运行终端的相关信息

可以使用**-m**选项。

$ who -m

对当前登录用户数量计数

如果系统同时有多人登录在线,-q 选项协助你完成计数功能。

$ who -q

附加空闲时间和PID信息

默认情况下who命令不会打印空闲时间和PID信息。如果打算显示这些信息使用-u选项。不要忘记使用 -H选项让显示的信息更加简单易读。

$ who -u -H

空闲时间 包含了最近最后一次活动以来消逝的时间. 所以00:13 意思是 用户leni已经13分钟没执行过命令了. (.)符号 是指该终端过去的一分钟有过活动。在那期间,我们称之为 “current” 。PID 是用户shell程序的进程ID号。

显示登录进程####

使用**-l**选项

$ who -l

第一列只显示系统登录守护进程的名字。上面截图中的数字 967, 971等是进程ID。

显示所有信息

使用**-a**选项会显示所有信息。例如:

$ who -a

####总结#### 你会发现 who 命令跟 w 命令在某些方面有些相像。不要为此感到疑惑为什么linux要实现这些在功能上相近的命令。你可以使用你觉得最适合你的或者适用于某种场合的命令。请查阅who命令手册了解更多详细信息。


via: http://linoxide.com/linux-command/linux-who-command/

译者:l3b2w1 校对:Caroline

本文由 LCTT 原创翻译,Linux中国 荣誉推出