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
ldapsearchcommand and include the--sortOrderoption.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
--sortOrderas 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
ldapsearchcommand searches for children in theou=People,dc=example,dc=comsubtree and sorts them first bysn(ascending) and then bygivenName(descending):$ bin/ldapsearch --baseDN ou=People,dc=example,dc=com \ --searchScope sub --sortOrder sn,-givenName '(objectclass=*)' -