PingDirectory

Searching for all children of an entry in sorted order

Steps

  • To search for all children of an entry in the appropriate subtree and sort the results by one or more attributes, run the ldapsearch command and include the --sortOrder option.

    Choose from:

    • To sort the results in ascending order, supply an attribute name for the value of --sortOrder.

    • To sort the results in descending order, supply an attribute name preceded by a - for the value of --sortOrder.

    • To sort the results by multiple attributes, supply the attribute names for the value of --sortOrder as follows:

      • List the attributes in the order in which you want to sort the results.

      • Separate the attributes with commas.

      • Remember to prepend - to any attributes that represent a descending sort.

    Example

    For this example, the ldapsearch command searches for children in the ou=People,dc=example,dc=com subtree and sorts them first by sn (ascending) and then by givenName (descending):

    $ bin/ldapsearch --baseDN ou=People,dc=example,dc=com \
      --searchScope sub --sortOrder sn,-givenName '(objectclass=*)'