LDAPSEARCH(1)

๐Ÿ’– LDAPSEARCH(1) ๐Ÿ’–

okay bestie, so this is a General Commands Manual page, and it's literally the manual for ldapsearch, the LDAP search tool. it's long, so we're doing this in parts โ€” this is part 1, don't go anywhere ๐Ÿซถ


โœจ NAME โœจ

ldapsearch โ€” the LDAP search tool, periodt ๐Ÿ‘‘


๐ŸŒธ SYNOPSIS ๐ŸŒธ

ldapsearch [-V[V]] [-d debuglevel] [-n] [-v] [-c] [-u] [-t[t]] [-T path]
[-F prefix] [-A] [-L[L[L]]] [-S attribute] [-b searchbase]
[-s {base|one|sub|children}] [-a {never|always|search|find}]
[-l timelimit] [-z sizelimit] [-f file] [-M[M]] [-x] [-D binddn] [-W]
[-w passwd] [-y passwdfile] [-H ldapuri] [-P {2|3}]
[-e [!]ext[=extparam]] [-E [!]ext[=extparam]] [-o opt[=optparam]]
[-O security-properties] [-I] [-Q] [-N] [-U authcid] [-R realm]
[-X authzid] [-Y mech] [-Z[Z]] filter [attrs...]

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

so ldapsearch is a shell-accessible interface to the ldap_search_ext(3) library call. slay ๐Ÿ’…

it opens a connection to an LDAP server, binds, and performs a search using the parameters you gave it. that's the whole vibe. the filter needs to conform to the string representation for search filters as defined in RFC 4515. if you don't hand it a filter, it just uses the default filter, (objectClass=*). no thoughts, head empty, default behaviour.

if ldapsearch finds one or more entries, the attributes you listed in attrs get returned. here's the tea on attrs:

  • if * is listed โ€” all user attributes come back โœจ
  • if + is listed โ€” all operational attributes come back ๐Ÿ”ฅ
  • if no attrs are listed at all โ€” all user attributes come back (yes, same as *)
  • if only 1.1 is listed โ€” literally no attributes will be returned, it's giving minimalism ๐Ÿ’€

the search results get displayed using an extended version of LDIF. and the -L option is the one that controls the format of the output. iykyk.


๐ŸŽ€ OPTIONS ๐ŸŽ€

  • -V[V] โ€” print version info. if you do -VV, it exits right after giving you the version info. otherwise it just keeps going and does the search you asked for ๐ŸŒˆ
  • -d debuglevel โ€” set the LDAP debugging level to debuglevel. heads up bestie: ldapsearch has to be compiled with LDAP_DEBUG defined for this option to do literally anything. no LDAP_DEBUG, no effect, no cap.
  • -n โ€” show what would be done, but don't actually perform the search. it's a dress rehearsal. super useful for debugging when you pair it with -v ๐Ÿ‘€
  • -v โ€” run in verbose mode, with a whole bunch of diagnostics written to standard output. she's chatty ๐Ÿ’ฌ
  • -c โ€” continuous operation mode. errors get reported, but ldapsearch keeps on doing searches anyway โ€” she does not stop, she does not fold. the default is to exit right after reporting an error. only useful in conjunction with -f.
  • -u โ€” include the User Friendly Name form of the Distinguished Name (DN) in the output ๐Ÿซถ
  • -t[t] โ€” a single -t writes retrieved non-printable values to a set of temporary files. this is the move for dealing with values that contain non-character data, like jpegPhoto or audio. a second -t writes all retrieved values to files. two t's, double the files โœจ
  • -T path โ€” write temporary files to the directory specified by path (default: the system default tmp directory). the environment variables TMPDIR, TMP, or TEMP will override the default path. ๐Ÿ“
  • -F prefix โ€” URL prefix for temporary files. the default is file://path where path is the system default tmp directory, or whatever you set with -T.
  • -A โ€” retrieve attributes only, no values. this is your girl when you just wanna know if an attribute is present in an entry and you do not care about the specific values. presence check queen ๐Ÿ‘‘
  • -L โ€” search results are displayed in LDAP Data Interchange Format, detailed over in ldif(5). here's how the stacking works:
    • a single -L restricts the output to LDIFv1
    • a second -L disables comments
    • a third -L disables printing of the LDIF version
    • the default is to use an extended version of LDIF ๐Ÿ’…
  • -S attribute โ€” sort the entries returned based on attribute. the default is to not 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. also, heads up: ldapsearch normally prints out entries as it receives them, but using -S defeats this behavior โ€” it causes all entries to be retrieved, then sorted, then printed. so she collects first, sorts later. different energy entirely.
  • -b searchbase โ€” use searchbase as the starting point for the search instead of the default. where you begin, bestie ๐ŸŒธ
  • -s {base|one|sub|children} โ€” specify the scope of the search as one of base, one, sub, or children, for a base object, one-level, subtree, or children search respectively. the default is sub. note: children scope requires the LDAPv3 subordinate feature extension. don't skip that note ๐Ÿงš
  • -a {never|always|search|find} โ€” specify how aliases dereferencing is done. it should be one of never, always, search, or find, to specify that aliases are never dereferenced, always dereferenced, dereferenced when searching, or dereferenced only when locating the base object for the search. the default is to never dereference aliases. never never never ๐Ÿ’…
  • -l timelimit โ€” wait at most timelimit seconds for a search to complete. a timelimit of 0 (zero) or none means no limit. a timelimit of max means the maximum integer allowable by the protocol. a server may impose a maximal timelimit which only the root user may override. โฐ
  • -z sizelimit โ€” retrieve at most sizelimit entries for a search. a sizelimit of 0 (zero) or none means no limit. a sizelimit of max means the maximum integer allowable by the protocol. a server may impose a maximal sizelimit which only the root user may override.
  • -f file โ€” read a series of lines from file, performing one LDAP search for each line. in this case, the filter given on the command line is treated as a pattern where the first and only occurrence of %s is replaced with a line from file. any other occurrence of the % character in the pattern will be regarded as an error. where it is desired that the search filter include a % character, the character should be encoded as \25 (see RFC 4515). also, if file is a single - character, then the lines are read from standard input. ldapsearch will exit when the first non-successful search result is returned, unless -c is used. ๐Ÿ”
  • -M[M] โ€” enable manage DSA IT control. -MM makes the control critical. two M's, critical M energy โš ๏ธ
  • -x โ€” use simple authentication instead of SASL. keeping it classic.
  • -D binddn โ€” use the Distinguished Name binddn to bind to the LDAP directory. for SASL binds, the server is expected to ignore this value. so like, don't count on it there ๐Ÿ™ˆ
  • -W โ€” prompt for simple authentication. this is used instead of specifying the password on the command line. safer, bestie, please use this ๐Ÿ”
  • -w passwd โ€” use passwd as the password for simple authentication.
  • -y passwdfile โ€” use the complete contents of passwdfile as the password for simple authentication.
  • -H ldapuri โ€” specify URI(s) referring to the ldap server(s); a list of URI, separated by whitespace or commas, is expected; only the protocol/host/port fields are allowed. as an exception, if no host/port is specified, but a DN is, the DN is used to look up the corresponding host(s) using the DNS SRV records, according to RFC 2782. the DN must be a non-empty sequence of AVAs whose attribute type is "dc" (domain component), and must be escaped according to RFC 2396. ๐ŸŒ
  • -P {2|3} โ€” specify the LDAP protocol version to use.
  • -e [!]ext[=extparam]
  • -E [!]ext[=extparam]

specify general extensions with -e and search extensions with -E. ! indicates criticality.

general extensions:

[!]assert=<filter>    (an RFC 4515 Filter)
!authzid=<authzid>    ("dn:<dn>" or "u:<user>")
[!]bauthzid           (RFC 3829 authzid control)
[!]chaining[=<resolve>[/<cont>]]
[!]manageDSAit
[!]noop
ppolicy
[!]postread[=<attrs>] (a comma-separated attribute list)
[!]preread[=<attrs>]  (a comma-separated attribute list)
[!]relax
sessiontracking[=<username>]
abandon,cancel,ignore (SIGINT sends abandon/cancel,
or ignores response; if critical, doesn't wait for SIGINT.
not really controls)

search extensions:

!dontUseCopy
[!]domainScope                       (domain scope)
[!]mv=<filter>                       (matched values filter)
[!]pr=<size>[/prompt|noprompt]       (paged results/prompt)
[!]sss=[-]<attr[:OID]>[/[-]<attr[:OID]>...]  (server side sorting)
[!]subentries[=true|false]           (subentries)
[!]sync=ro[/<cookie>]                (LDAP Sync refreshOnly)
        rp[/<cookie>][/<slimit>]     (LDAP Sync refreshAndPersist)
[!]vlv=<before>/<after>(/<offset>/<count>|:<value>)  (virtual list view)
[!]deref=derefAttr:attr[,attr[...]][;derefAttr:attr[,attr[...]]]
[!]accountUsability                  (Netscape Password policy)
[!]<oid>[=:<value>|=::<b64value>]
  • -o opt[=optparam] โ€” specify any ldap.conf(5) option, or one of the following:
nettimeout=<timeout>  (in seconds, or "none" or "max")
ldif_wrap=<width>     (in columns, or "no" for no wrapping)
  • -O security-properties โ€” specify SASL security properties.
  • -I โ€” enable SASL Interactive mode. always prompt. the default is to prompt only as needed. she's asking every time, no skipping ๐Ÿ™‹
  • -Q โ€” enable SASL Quiet mode. never prompt. the opposite girlie, she says nothing ๐Ÿค
  • -N โ€” do not use reverse DNS to canonicalize the SASL host name.
  • -U authcid โ€” specify the authentication ID for SASL bind. the form of the ID depends on the actual SASL mechanism used.
  • -R realm โ€” specify the realm of authentication ID for SASL bind. the form of the realm depends on the actual SASL mechanism used.
  • -X authzid โ€” specify the requested authorization ID for SASL bind. authzid must be one of the following formats: dn:<distinguished name> or u:<username>
  • -Y mech โ€” specify the SASL mechanism to be used for authentication. if it's not specified, the program will choose the best mechanism the server knows. she'll pick for you, trust ๐Ÿ’…
  • -Z[Z] โ€” issue StartTLS (Transport Layer Security) extended operation. if you use -ZZ, the command will require the operation to be successful. no success, no search โ€” she's strict about that one ๐Ÿ”’

๐ŸŒˆ OUTPUT FORMAT ๐ŸŒˆ

if one or more entries are found, each entry is written to standard output in LDAP Data Interchange Format or ldif(5):

version: 1

# bjensen, example, net
dn: uid=bjensen,dc=example,dc=net
objectClass: person
objectClass: dcObject
uid: bjensen
cn: Barbara Jensen
sn: Jensen
...

if the -t option is used, the URI of a temporary file is used in place of the actual value. and if the -A option is given, only the "attributename" part is written. that's it, that's the output situation โœจ


(part 1 done bestie โ€” more coming, stay tuned ๐Ÿซถ)

๐ŸŒˆ EXAMPLE ๐ŸŒˆ

okay bestie, real talk, examples are where it all clicks, so let's go ๐Ÿ’…

This command right here:

ldapsearch -LLL "(sn=smith)" cn sn telephoneNumber

is gonna do a subtree search (using the default search base and all the other parameters that live in ldap.conf(5), obvs) for entries with a surname (sn) of smith. Then it pulls back the common name (cn), surname (sn) and telephoneNumber values and prints them to standard output. If it finds two entries, the output is giving something like this:

dn: uid=jts,dc=example,dc=com
cn: John Smith
cn: John T. Smith
sn: Smith
sn;lang-en: Smith
sn;lang-de: Schmidt
telephoneNumber: 1 555 123-4567

dn: uid=sss,dc=example,dc=com
cn: Steve Smith
cn: Steve S. Smith
sn: Smith
sn;lang-en: Smith
sn;lang-de: Schmidt
telephoneNumber: 1 555 765-4321

look at those two Smiths thriving ๐Ÿซถ


Now this command:

ldapsearch -LLL -u -t "(uid=xyz)" jpegPhoto audio

does a subtree search using the default search base for entries with a user id of "xyz". The user friendly form of the entry's DN gets output after the line that contains the DN itself (that's the -u girlies), and the jpegPhoto and audio values get retrieved and written to temporary files (that's -t doing her thing). If one entry with one value for each of the requested attributes turns up, the output might look like:

dn: uid=xyz,dc=example,dc=com
ufn: xyz, example, com
audio:< file:///tmp/ldapsearch-audio-a19924
jpegPhoto:< file:///tmp/ldapsearch-jpegPhoto-a19924
notice the ufn: line? that's the user friendly name, nestled right in there ๐Ÿ’–

And this command:

ldapsearch -LLL -s one -b "c=US" "(o=University*)" o description

performs a one-level search at the c=US level for all entries whose organization name (o) begins with University. The organization name and description attribute values get retrieved and printed to standard output, and the result is giving something like:

dn: o=University of Alaska Fairbanks,c=US
o: University of Alaska Fairbanks
description: Naturally Inspiring
description: leaf node only

dn: o=University of Colorado at Boulder,c=US
o: University of Colorado at Boulder
description: No personnel information
description: Institution of education and research

dn: o=University of Colorado at Denver,c=US
o: University of Colorado at Denver
o: UCD
o: CU/Denver
o: CU-Denver
description: Institute for Higher Learning and Research

dn: o=University of Florida,c=US
o: University of Florida
o: UFl
description: Warper of young minds

...

not the ... at the end, meaning yes bestie there are MORE universities, this list goes on and on, she's a long one โœจ


๐Ÿ’€ DIAGNOSTICS ๐Ÿ’€

Exit status is zero if no errors occur. If errors DO occur? You get a non-zero exit status and a diagnostic message written to standard error. so check your $? before you celebrate, okay? ๐Ÿ™ˆ


๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

ldapadd(1), ldapdelete(1), ldapmodify(1), ldapmodrdn(1), ldap.conf(5), ldif(5), ldap(3), ldap_search_ext(3), ldap_sort(3)

the whole squad, all linked up, iykyk ๐ŸŽ€


๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

The OpenLDAP Project <http://www.openldap.org/>

periodt. that's the author. iconic.


๐Ÿซถ ACKNOWLEDGEMENTS ๐Ÿซถ

OpenLDAP Software is developed and maintained by The OpenLDAP Project <http://www.openldap.org/>. OpenLDAP Software is derived from the University of Michigan LDAP 3.3 Release.

like, shoutout to Michigan fr fr, ancestors of the whole thing ๐ŸŒธ


okay bestie that's the whole page, you read the ENTIRE manual page and that's main character energy, no cap ๐Ÿฆ‹ this was OpenLDAP 2.7.2, dated 2026/10/21, and it's the LDAPSEARCH(1) page โ€” go forth and search, you absolute legend ๐Ÿ’…๐Ÿ’–โœจ

๐Ÿ“ฆ where this page comes from