This section covers utilities that display who is using the system, what those users are doing, and how the system is running. To find out who is using the local system, you can employ one of several utilities that vary in the details they provide and the options they support. The oldest utility, who, produces a list of users who are logged in on the local system, the terminal connection each person is using, and the time the person logged in.
The w and finger utilities show more detail, such as each user's full name and the command line each user is running. You can use the finger utility (page 401) to retrieve information about users on remote systems if your computer is attached to a network. Table 3-1 on page 63 summarizes the output of these utilities.
who: Lists Users on the System
The who utility displays a list of users who are logged in. In Figure 3-10 the first column of who shows that Zach and Max are logged in. (Zach is logged in both from the console and from two virtual terminals, probably running Terminal sessions.) The second column shows the device that each user's terminal, workstation, or terminal emulator is connected to. The third column shows the date and time the user logged in. An optional fourth column shows in parentheses the name of the system that a remote user logged in from.
Figure 3-10. who lists who is logged in
$ who zach console Mar 21 21:10 zach ttyp1 Mar 24 01:07 zach ttyp2 Mar 30 00:32 (localhost) max ttyp3 Mar 30 01:11 (bravo)
The information that who displays is useful when you want to communicate with a user at your installation. When the user is logged in, you can use write (page 63) to establish communication immediately. If who does not list the user or if you do not need to communicate immediately, you can send email to that person (page 64).
If the output of who scrolls off the screen, you can redirect the output through a pipe (|, page 51) so that it becomes the input to less, which displays the output one page at a time. You can also use a pipe to redirect the output through grep to look for a specific name.
If you need to find out which terminal you are using or what time you logged in, you can use the command who am i:
$ who am i max ttyp3 Mar 30 01:11 (localhost)
finger: Lists Users on the System
Security: finger can be a security risk
By default Mac OS X has remote finger support disabled, so that only local users can use finger to display information about local users. This utility can give information that can help a malicious user break into the system.
You can use finger to display a list of the users who are logged in on the system. In addition to usernames, finger supplies each user's full name along with information about which device the user's terminal is connected to, how recently the user typed something on the keyboard, when the user logged in, and any contact information stored in the user database. See Figure 3-11.
Figure 3-11. finger I: lists who is logged in
$ finger Login Name TTY Idle Login Time Office Phone max Max p3 Wed 01:11 zach Zach con 8d Mar 21 21:10 zach Zach p1 Mar 24 01:07 zach Zach p2 1 Wed 00:32
You can also use finger to learn more about a particular individual by specifying more information on the command line. In Figure 3-12, finger displays detailed information about the user named Max. Max is logged in and actively using his terminal. If Max were not actively using his terminal, finger would report how long he had been idle. You also learn from finger that if you want to set up a meeting with Max, you should contact Sam.
Figure 3-12. finger II: lists details about one user
$ finger max Login: max Name: Max Directory: /Users/max Shell: /bin/bash On since Wed Mar 30 01:11 (CST) on ttyp3 (messages off) from localhost No Mail. Plan: Out of town this week, contact Sam if you need to see me.
.plan and .project
Most of the information in Figure 3-12 was collected by finger from system files. The information shown after the heading Plan:, however, was supplied by Max. The finger utility searched for a file named .plan in Max's home directory and displayed its contents. (Filenames that begin with a period, such as .plan, are not normally listed by ls and are not displayed by the Finder; they are called invisible filenames [page 76].) You may find it helpful to create a .plan file for yourself; it can contain any information you choose, such as your typical schedule, interests, phone number, or address. In a similar manner, finger displays the contents of the .project file in your home directory. If Max had not been logged in, finger would have reported the last time he logged in, the last time he read his email, and his plan.
You can use finger to display a user's username. For example, on a system with a user named Helen Simpson, you might know that Helen's last name is Simpson but might not guess that her username is hls. The finger utility, which is not case sensitive, can search for information on Helen using her first or last name. The following commands find the information you seek as well as information on other users whose names are Helen or Simpson.
$ finger HELEN Login: hls Name: Helen Simpson. ... $ finger simpson Login: hls Name: Helen Simpson. ...
w: Lists Users on the System
The w utility displays a list of the users who are logged in. As discussed in the section on who, the information that w displays is useful when you want to communicate with someone at your installation.
The first column in Figure 3-13 shows that Zach and Max are logged in. The second column shows the designation of the device that each user's terminal is connected to. The third column shows the system that a remote user is logged in from. The fourth column shows the time each user logged in. The fifth column indicates how long each user has been idle (how much time has elapsed since the user pressed a key on the keyboard). The last column shows the command each user is running.
Figure 3-13. The w utility
$ w 1:19 up 8 days, 4:11, 4 users, load averages: 0.00 0.00 0.00 USER TTY FROM LOGIN@ IDLE WHAT zach console - 21Mar05 8days - zach p1 bravo.example.co Thu01 - ssh zach p2 - 0:32 8 bash max p3 localhost 1:11 - w
The first line that the w utility displays includes the time of day, the period of time the computer has been running (in days, hours, and minutes), the number of users logged in, and the load average (how busy the system is). The three load average numbers represent the number of jobs waiting to run, averaged over the past 1, 5, and 15 minutes. Table 3-1 compares the w, who, and finger utilities.