Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wish to count the number of objects returned from a query (but I do not need the actual objects themselves) from Sun Java System Directory Server 5.2.

E.g., if I want to find all people with surname Smith, I would want something like

ldapsearch -LLL -H ldaps:// -b "ou=people,dc=example,dc=com" "sn=Smith"

but with some sort of count. Is this possible without returning all of the results?

share|improve this question
Not a direct answer, but you could just ask for 'dn' to be returned, reducing the size of the response. – Joe H. Mar 5 '12 at 15:09

Either append the ldapentrycount option to the end:

ldapsearch -LLL -H ldaps:// -b "ou=people,dc=example,dc=com" "sn=Smith" ldapentrycount

or parse the numEntries value from the results:

ldapsearch -LLL -H ldaps:// -b "ou=people,dc=example,dc=com" "sn=Smith" ldapentrycount | awk '/numEntries: / { print $3 }'

Is this what you're looking for?

share|improve this answer

One word of caution -- you can count the number of objects returned from the query, but that may not be the same as the number of objects matched, as there may be limits on the number of objects returned. You can add -z 0 to try to remove a soft limit.

I'd personally go with something like:

ldapsearch -LLL -z 0 -H ldaps:// -b "ou=people,dc=example,dc=com" "sn=Smith" dn | grep ^dn: | wc -l
share|improve this answer
Even with removing the soft limit, I get 11: Administrative limit exceeded. – cubetwo1729 Mar 5 '12 at 15:50
@cubetwo1729 : You might have a different limit if you also send authentication information. It's been years since I've done admin work for a Sun Directory server (shortly after they went from iPlanet to SunOne), but I seem to remember having set up a dn to bind as for searching that had higher limits. – Joe H. Mar 5 '12 at 16:10
"administrative limit exceeded" on DSEE means the client has exceeded the lookthroughlimit, which is a server-side limit on the number of entries the server will examine when constructing the candidate list of entries that match the query. – Terry Gardner Aug 24 '12 at 7:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.