此内容没有您所选择的语言版本。
3.4.6. Displaying Comprehensive User Information
When administering users and groups on your system, you need a good tool to monitor their configuration and activity on the system. Red Hat Enterprise Linux 6 provides you with the lslogins command-line utility, which gives you a comprehensive overview of users and groups, not only regarding user or group account configuration but also their activity on the system.
The general syntax of lslogins is the following:
lslogins [OPTIONS]
lslogins [OPTIONS]lslogins [OPTIONS]lslogins [OPTIONS]
where OPTIONS can be one or more available options and their related parameters. See the
lslogins
(1) manual page or the output of the lslogins --help
command for the complete list of available options and their usage.
The lslogins utility gives versatile information in a variety of formats based on the chosen options. The following examples introduce the most basic as well as some of the most useful combinations.
Running the
lslogins
command without any options shows default information about all system and user accounts on the system. Specifically, their UID, user name, and GECOS information, as well as information about the user's last login to the system, and whether their password is locked or login by password disabled.
Example 3.13. Displaying basic information about all accounts on the system
To display detailed information about a single user, run the
lslogins LOGIN
command, where LOGIN is either a UID or a user name. The following example displays detailed information about John Doe
's account and his activity on the system:
Example 3.14. Displaying detailed information about a single account
If you use the
--logins=LOGIN
option, you can display information about a group of accounts that are specified as a list of UIDs or user names. Specifying the --output=COLUMNS
option, where COLUMNS is a list of available output parameters, you can customize the output of the lslogins
command. For example, the following command shows login activity of the users root, jsmith, jdoe, and esmith:
Example 3.15. Displaying specific information about a group of users
The lslogins utility also distinguishes between system and user accounts. To address system accounts in your query, use the
--system-accs
option. To address user accounts, use the --user-accs
. For example, the following command displays information about supplementary groups and password expirations for all user accounts:
Example 3.16. Displaying information about supplementary groups and password expiration for all user accounts
The ability to format the output of
lslogins
commands according to the user's needs makes lslogins an ideal tool to use in scripts and for automatic processing. For example, the following command returns a single string that represents the time and date of the last login. This string can be passed as input to another utility for further processing.
Example 3.17. Displaying a single piece of information without the heading
lslogins --logins=jsmith --output=LAST-LOGIN --time-format=iso | tail -1
~]# lslogins --logins=jsmith --output=LAST-LOGIN --time-format=iso | tail -1
2014-08-06T10:56:12+0200