mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
Merge pull request #28364 from lkxed/20230102-1-who-Command-in-Linux-Explanation-with-Examples
[手动选题][tech]: 20230102.1 ⭐️ who Command in Linux Explanation with Examples.md
This commit is contained in:
commit
cc8ce0715f
@ -0,0 +1,138 @@
|
||||
[#]: 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: " "
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
who Command in Linux: Explanation with Examples
|
||||
======
|
||||
|
||||
**Here’s a beginner’s 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 user’s 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 user’s 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
|
Loading…
Reference in New Issue
Block a user