4 ways to view your system's current logged-on user information under Linux

Source: Internet
Author: User
Tags time and date

4 ways to view your system's current logged-on user information under Linux

As a system administrator, you can often (at some point) need to see which users in your system are active. Sometimes you even need to know what they are doing. This article summarizes 4 ways to view system user information (by number (ID)).

1. Use the W command to view the process information that the logged on user is using

The W command is used to display the names of the users who have logged in to the system and what they are doing. The information used by this command originates from the/var/run/utmp file. The information for the W command output includes:
? user Name
? user's machine name or TTY number
? Remote Host Address
? When the user logs on to the system
Idle time (little effect)
Time spent in a process attached to a TTY (terminal) (Jcpu time)
The current process time (pcpu time)
? The command the user is currently using

The

W command can also use the following options
?-H Ignores header file information
?-U Displays the load time of the results
?-S does not display JCPU, PCPU, Login time
$ w
 23:04:27 up days,  7:51,  3 users,  Load average:0.04, 0.06, 0.02
user     tty    & nbsp from              [email protected]    idle   jcpu   PCPU what
ramesh   pts/0    dev-db-server         22:57    8.00s  0.05s  0.01s sshd:ramesh [Priv]
jason    pts/1    dev-db-server        23:01     2:53   0.01s  0.01s-bash
john     pts/2    dev-db-server        23:04    0.00s  0.00s  0.00s w

$ w-h
ramesh   pts/0    dev-db-server        22:57   17:43   2.52s  0.01s sshd:ramesh [priv]
jason    pts/1     dev-db-server        23:01   20:28   0.01s   0.01s-bash
john     pts/2    dev-db-server         23:04    0.00s  0.03s  0.00s w-h

$ w-u
 23:22:06 up days,  8:08,  3 users,  load average:0.00, 0.00, 0.00
USER &NBSP ;   tty      from               [email protected]   idle   jcpu   PCPU what
ramesh    pts/0    dev-db-server        22:57   17:47    2.52s  2.49s Top
jason    pts/1    dev-db-server         23:01   20:32   0.01s  0.01s-bash
john      pts/2    dev-db-server        23:04     0.00s  0.03s  0.00s w-u

$ w-s
23:22:10 up-Days, 8:08, 3 users, Load average:0.00, 0.00, 0.00
USER TTY from IDLE
Ramesh pts/0 dev-db-server 17:51 Sshd:ramesh [Priv]
Jason Pts/1 Dev-db-server 20:36-bash
John Pts/2 Dev-db-server 1.00s w-s



2. Use the WHO command to view (log in) the user name and the process that was started

The WHO command is used to enumerate the user names of the currently logged on system. The output is: User name, TTY number, time date, host address.

$ who
Ramesh pts/0 2009-03-28 22:57 (dev-db-server)
Jason Pts/1 2009-03-28 23:01 (dev-db-server)
John Pts/2 2009-03-28 23:04 (dev-db-server)
If you only want to list users, you can use the following statement:

$ who | Cut-d '-f1 | Sort | Uniq
John
Jason
Ramesh
Supplemental: The users command, which can be used to print out the user name of the logon server. This command has no options other than the Help and version options. If a user uses more than one terminal, multiple duplicate user names are displayed accordingly.

$ users
John Jason Ramesh


3. Use the WhoAmI command to see the login name you are using


The WhoAmI command is used to display the logged-in user name.

$ whoami
John
The WhoAmI command performs exactly the same as the Id-un effect, for example:

$ id-un
John
The WhoAmI command displays the name of the user currently logged in and the TTY information currently being used. The output of this command includes the following: User name, TTY name, current time date, and also the link address used by the user to log on to the system.

$ Who am I
John Pts/2 2009-03-28 23:04 (dev-db-server)

$ who mom likes
John Pts/2 2009-03-28 23:04 (dev-db-server)

Warning:don ' t try "who mom hates" command.
Of course, if you use the SU command to change the user, the results displayed by the command (WHOAMI) will change.



4. Always view the system's historical information (user information that was used by the system)


The last command can be used to display the history of a particular user's login system. If no parameters are specified, the history information for all users is displayed. By default, this information (the information displayed) is derived from the/var/log/wtmp file. The output of this command contains the following columns of information:
? user Name
? TTY device number
? history Login Time Date
? Log out time and date
? Total working hours
$ last Jason
Jason Pts/0 dev-db-server Fri Mar 22:57 still logged in
Jason Pts/0 dev-db-server Fri Mar 27 22:09-22:54 (00:45)
Jason Pts/0 dev-db-server Wed Mar 25 19:58-22:26 (02:28)
Jason Pts/1 dev-db-server Mon Mar 16 20:10-21:44 (01:33)
Jason Pts/0 192.168.201.11 Fri Mar 13 08:35-16:46 (08:11)
Jason Pts/1 192.168.201.12 Thu Mar 12 09:03-09:19 (00:15)
Jason Pts/0 dev-db-server Wed Mar 11 20:11-20:50 (00:39


This article is from the "Paraquat Susan" blog, so be sure to keep this source http://suxin.blog.51cto.com/535505/1836758

4 ways to view your system's current logged-on user information under Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.