Merge pull request #28402 from geekpi/translating

translated
This commit is contained in:
geekpi 2023-01-10 09:23:33 +08:00 committed by GitHub
commit 2b247b2ad0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 132 additions and 138 deletions

View File

@ -1,138 +0,0 @@
[#]: subject: "who Command in Linux: Explanation with Examples"
[#]: via: "https://www.debugpoint.com/who-command-linux/"
[#]: author: "Arindam https://www.debugpoint.com/author/admin1/"
[#]: collector: "lkxed"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
who Command in Linux: Explanation with Examples
======
**Heres a beginners guide on understanding who command in Linux with several examples.**
_This article is part of the [Linux command][1] learning series._
### who command
The “who” command in Linux is used to display information about users who are currently logged in to the system. It shows the users login name, the terminal from which the user is logged in, the time at which the user logged in, and the remote hostname (if applicable).
#### Syntax
Here is the basic syntax for the “who” command:
```
who [OPTION]... [ FILE | ARG1 ARG2 ]
```
### Example of various who command and switches
By default, “who” reads the file `/var/run/utmp`, which contains information about users who are currently logged in. If no options are specified, it displays each users login name, terminal, and time of login.
```
who
```
It gives the following output. As you can see it shows the login name=debugpoint, terminal id tty2 and the date and time of the login.
```
debugpoint tty2 2023-01-01 11:22 (tty2)
```
![who command - default example][2]
However, if you run the above command in a guest virtual machine, you should see the same but the terminal id would be the x11 server display name i.e. :0.
```
whodebugpoint :0 2023-01-01 23:36 (:0)
```
To show the username of the current user and information, use below:
```
whoami
```
View the last system boot time using the -b option:
```
who -bsystem boot 2023-01-01 23:36
```
Display the count of users logged in the current system:
```
who -qdebugpointusers=1
```
All the above command when paired with -H option, you get a better info with a header line, like below:
```
who -H
NAME LINE TIME COMMENT
debugpoint tty2 2023-01-01 11:22 (tty2)
```
If you want to display all the information related to who command in Linux, use the option -a:
```
who -aH
NAME LINE TIME IDLE PID COMMENT EXIT
system boot 2023-01-01 11:19
run-level 5 2023-01-01 11:19
debugpoint + tty2 2023-01-01 11:22 13:26 2042 (tty2)
```
As always, you can save the output of the who command to any file using the redirect as below:
```
who > user_details.txt
```
#### Example summary of who command options
Here are some who command examples and their explanation:
Here are some options that can be used with the “who” command:
- `-a`: Display the hostname, time of login, and processes for each user
- `-b`: Display the time of the last system boot
- `-d`: Display dead processes (processes that have terminated but have not been removed from the utmp file)
- `-H`: Display a header line
- `-l`: Display login processes in long format
- `-m`: Display only the name and line of the user who is logged in on the terminal specified by `ARG1 ARG2`
- `-q`: Display a count of logged in users
- `-u`: Display information about users who have processes that are not detached
- `-w`: Display information about users who are logged in, in the same format as the utmp file
### Closing Notes
I hope this article helps you to understand who command and its basics. You can also read the [who man pages][3] to learn more. Let me know if you have any questions.
**This article is part of the [Linux command][1] learning series**.
[Next:How to Force Auto Dark Mode in Chrome and Chromium][4]
[_Using Mastodon? Follow us at floss.social/@debugpoint_][5]
--------------------------------------------------------------------------------
via: https://www.debugpoint.com/who-command-linux/
作者:[Arindam][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.debugpoint.com/author/admin1/
[b]: https://github.com/lkxed
[1]: https://www.debugpoint.com/category/linux-commands
[2]: https://www.debugpoint.com/wp-content/uploads/2023/01/who-command-default-example.jpg
[3]: https://man7.org/linux/man-pages/man1/who.1.html
[4]: https://www.debugpoint.com/chrome-dark-mode/
[5]: https://floss.social/@debugpoint

View File

@ -0,0 +1,132 @@
[#]: subject: "who Command in Linux: Explanation with Examples"
[#]: via: "https://www.debugpoint.com/who-command-linux/"
[#]: author: "Arindam https://www.debugpoint.com/author/admin1/"
[#]: collector: "lkxed"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Linux 中的 who 命令:解释与示例
======
**这里是一个关于理解 Linux 中 who 命令的初学者指南,并有几个例子。**
_这篇文章是 [Linux 命令][1]学习系列的一部分。_
### who 命令
Linux中的 “who” 命令用于显示当前登录到系统中的用户的信息。它显示用户的登录名,用户登录的终端,用户登录的时间,以及远程主机名(如果有)。
#### 语法
下面是 “who” 命令的基本语法:
```
who [OPTION]... [ FILE | ARG1 ARG2 ]
```
### 各种 who 命令和开关的例子
默认情况下“who” 读取文件 `/var/run/utmp`,其中包含当前登录的用户的信息。如果没有指定选项,它会显示每个用户的登录名、终端和登录时间。
```
who
```
它给出了以下输出。你可以看到它显示了登录名是 debugpoint终端ID tty2 和登录的日期和时间。
```
debugpoint tty2 2023-01-01 11:22 (tty2)
```
![who 命令 - 默认示例][2]
然而,如果你在虚拟机中运行上述命令,你应该看到同样的情况,但终端 ID 将是 x11 服务器的显示名称0。
```
whodebugpoint :0 2023-01-01 23:36 (:0)
```
要显示当前用户的用户名和信息,使用下面的方法:
```
whoami
```
使用 -b 选项查看最后一次系统启动时间:
```
who -bsystem boot 2023-01-01 23:36
```
显示当前系统中登录的用户数:
```
who -qdebugpointusers=1
```
所有上述命令与 -H 选项配对时,你会有一个更好的含标题行的信息,如下所示:
```
who -H
NAME LINE TIME COMMENT
debugpoint tty2 2023-01-01 11:22 (tty2)
```
如果你想在Linux中显示与who命令有关的所有信息请使用选项-a
```
who -aH
NAME LINE TIME IDLE PID COMMENT EXIT
system boot 2023-01-01 11:19
run-level 5 2023-01-01 11:19
debugpoint + tty2 2023-01-01 11:22 13:26 2042 (tty2)
```
像往常一样,你可以使用下面的重定向将 who 命令的输出保存到任何文件:
```
who > user_details.txt
```
#### who 命令选项的例子总结
下面是一些 who 命令的例子和它们的解释:
下面是一些可以与 “who” 命令一起使用的选项:
- `-a`: 显示每个用户的主机名、登录时间和进程
- `-b`: 显示上次系统启动的时间
- `-d`: 显示死进程(已终止但未从 utmp 文件中删除的进程)
- `-H`: 显示标题行
- `-l`: 显示长格式的登录进程
- `-m`: 只显示在 `ARG1 ARG2` 指定的终端上登录的用户的名字和行。
- `-q`: 显示已登录用户的数量
- `-u`: 显示拥有未分离进程的用户的信息
- `-w`: 显示已经登录的用户信息,格式与 utmp 文件相同
### 结尾说明
我希望这篇文章能够帮助你了解 who 命令及其基本原理。你也可以阅读 [who 手册页][3]来了解更多。如果你有任何问题,请告诉我。
**本文是 [Linux 命令][1]学习系列的一部分**。
--------------------------------------------------------------------------------
via: https://www.debugpoint.com/who-command-linux/
作者:[Arindam][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.debugpoint.com/author/admin1/
[b]: https://github.com/lkxed
[1]: https://www.debugpoint.com/category/linux-commands
[2]: https://www.debugpoint.com/wp-content/uploads/2023/01/who-command-default-example.jpg
[3]: https://man7.org/linux/man-pages/man1/who.1.html