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.
#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
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
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
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]
3) Enter: lastlog. This is for all users of the system. Most of them are built-in to the system.
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!