Home  >  Article  >  Operation and Maintenance  >  How to check the current user in Linux

How to check the current user in Linux

藏色散人
藏色散人Original
2023-01-05 15:00:5828748browse

The ways to view the current user in Linux are: 1. View the current user by entering the "who" command in the shell terminal; 2. View the current user by executing the "whoami" command in the shell terminal; 3. Execute the "w" command in the shell terminal to view the current user.

How to check the current user in Linux

#The operating environment of this tutorial: ubuntu 9.10 system, Dell G3 computer.

How to check the current user in Linux?

How to view the current user and all users under Linux

Note:
1. The following test is under Conducted on Ubuntu 9.10, other platforms have not been tested.
2. This is just my personal understanding and may not be completely correct
3. All rights reserved. Please indicate the author and source when reprinting

1. View current users

1. Enter in the shell terminal: who

The current user is: book, using the terminal of tty7, followed by the login time

2 , Enter in the shell terminal: whoami

The current user is: book, the output result is very concise

3. Enter in the shell terminal: w

The current user is: book, using the terminal of tty7, followed by some other information

How to check the current user in Linux

2. View all users

1. Users who log in normally have a home directory under /home, so they can directly view the files in this directory

Enter: ls /home

How to check the current user in Linux

2. General method: directly check the value of the second colon after the /etc/passwd file when it is greater than 1000, this is a user

1) Enter: cat /etc/passwd, too much information, not good Find

How to check the current user in Linux

2) Enter: cat /etc/passwd |cut -d: -f 1-3 , filter only Useful information is produced for easy viewing. [It is recommended to use this command]

How to check the current user in Linux

3) Enter: lastlog. This is for all users of the system. Most of them are built-in to the system.

How to check the current user in Linux

Recommended study: "Linux Video Tutorial"

The above is the detailed content of How to check the current user in Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn