How Can I List the Logged-In Users in UNIX?
UNIX uses different commands to perform different actions. The following table provides a list of commands that provide information about users currently logged into a UNIX machine, with their descriptions.
| Name | Description |
|---|---|
| w | Shows who all are logged in and what they are doing. It displays in summary format the processes of the current users using the machine and the load being exerted on the machine. It shows the current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes, in that order. It also shows the login name and idle time of logged-in users |
| who | Shows who all are logged in and where they are logged in. This command is especially useful in knowing the location of the person logged into a particular machine. It specifies the username, login time, terminal, process id, and the time since the last activity. The Single Unix Specification (SUS) specifies that the who command should list information about accessible users. The who command can be invoked with the arguments am and I; for example, who am I. |
| finger username | This command displays information about a particular user. For instance, whether the user is currently logged in, the last time the user opened a certain program, etc. Any information that was stored in the .plan file of the user will also be displayed. |
| last - l username | This command displays the last time the user logged on and off and their location at the time of logon. The last command by itself gives a list of all logins. |
You can therefore use either the w, who, or users command to know who all are logged into the system.
An example output of the w command may be as follows:
$ w
10:33am up 608 day(s), 19:56, 5 users, load average:
0.36, 0.36, 0.37
User tty login@ idle what
jamesf pts/5 8:52am w
maureenm pts/23 20Apr08 28 -bash
henryj pts/18 9:01am 9 pine
peterb pts/19 21Apr08 emacs -nw html/index.html
meganr pts/8 10:12am 3days -csh
andrewf pts/12 16Apr08 5:29 /usr/bin/perl -w
perl/test/program.pl
An example output of the who command:
$ who
jamesf ttyp0 Apr 26 08:11 (66.164.235.73)
maureenm ttyp3 Apr 26 20:26 (66.164.235.73)
An example output of the users command:
$ users
jamesf maureenm henryj peterb meganr andrewf
You can also list all UNIX users, including those who are not logged in; you can use the /etc/passwd file and the finger username or last - l username commands to get specific information about them. A typical entry in the /etc/passwd file looks like this:
root:*:0:0:System Administrator:/var/root:/bin/sh
You can then use the awk or cut utilities to trim this information to exactly what you want.
For example, to just see the Unix user names, use the command $ cat /etc/passwd | cut -d: -f1.
$ cat /etc/passwd | cut -d: -f1
...
jamesf
maureenm
...
Or, to only see their real names:
$ cat /etc/passwd | cut -d: -f5
...
James Forlon
Maureen Major
Bookmark How Can I List the Logged-In Users in UNIX?
