Display users and groups

A question arose about how to display users and groups in the same format as the following commands, but sort them in alphabetical order:

lsuser -fa id groups gecos admin account_locked maxage unsuccessful_login_count ALL
lsgroup -fa id admin users ALL

The problem is that with the -f option, each attribute is displayed on a line by itself, separate from the username. The answer, as with solving many such problems in UNIX, simply involves stringing together the right combination of UNIX commands:

lsuser -fa id groups gecos admin account_locked maxage unsuccessful_login_count `lsuser -a ALL | sort | paste -s -d ',' -`
lsgroup -fa id admin users `lsgroup -a ALL | sort | paste -s -d ',' -`

lsuser -a ALL and lsgroup -a ALL list all of the users or groups, with one on each line. sort sorts the list in alphabetical order, and paste -s -d ',' - concatenates it into one line to create a comma-delimited list, which is passed as a parameter to the command using back-quotes `...` ( aka grave accents). -fa displays each of the named attributes on a separate line. The list of attributes in the examples above are some of the ones that are useful for Sarbanes-Oxley audits.

Last updated Thursday January 4, 2007


Printer-friendly PDF* format:

Users and Groups

This Section

You are currently viewing this page in XHTML 1 Style Sheet* format (* see Clicklets for more infomation). This document is also available in XHTML 1*XML*HTML 4*HTML 5 Style Sheet*HTML 5 XML*HTML 5 non-XML* XHTML 2* XHTML Mobile* WML Mobile* and printer-friendly PDF* formats. This is accomplished with Single Source Publishing, a content management system that uses templates in XSLT style sheets provided by XML Styles .com to transform the source content for various content delivery channels. There is also RDF* metadata that describes the content of this document.