Ldap – how to use ldapsearch for sort attributes filter

ldap

I would like to know how to use ldapsearch filter for sort mail by gid number. I tried several command and I don't get what I expected. I got all the entry without sorting or nothing.

Best Answer

Use -S parameter (in your case, -S gid) in ldapsearch command. From the ldapsearch man page:

-S attribute Sort the entries returned based on attribute. The default is not to sort entries returned. If attribute is a zero-length string (""), the entries are sorted by the components of their Distinguished Name. See ldap_sort(3) for more details. Note that ldapsearch normally prints out entries as it receives them. The use of the -S option defeats this behavior, causing all entries to be retrieved, then sorted, then printed.