1LDAPSEARCH(1)               General Commands Manual              LDAPSEARCH(1)
2
3
4

NAME

6       ldapsearch - LDAP search tool
7

SYNOPSIS

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

DESCRIPTION

19       ldapsearch is a shell-accessible interface  to  the  ldap_search_ext(3)
20       library call.
21
22       ldapsearch  opens a connection to an LDAP server, binds, and performs a
23       search using specified parameters.   The filter should conform  to  the
24       string  representation  for  search filters as defined in RFC 4515.  If
25       not provided, the default filter, (objectClass=*), is used.
26
27       If ldapsearch finds one or more entries, the  attributes  specified  by
28       attrs  are returned.  If * is listed, all user attributes are returned.
29       If + is listed, all operational attributes are returned.  If  no  attrs
30       are  listed,  all user attributes are returned.  If only 1.1 is listed,
31       no attributes will be returned.
32
33       The search results are displayed using an  extended  version  of  LDIF.
34       Option -L controls the format of the output.
35

OPTIONS

37       -V[V]  Print  version info.  If -VV is given, exit after providing ver‐
38              sion info. Otherwise proceed with the specified search
39
40       -d debuglevel
41              Set the LDAP debugging level to debuglevel.  ldapsearch must  be
42              compiled with LDAP_DEBUG defined for this option to have any ef‐
43              fect.
44
45       -n     Show what would be done, but don't actually perform the  search.
46              Useful for debugging in conjunction with -v.
47
48       -v     Run  in  verbose mode, with many diagnostics written to standard
49              output.
50
51       -c     Continuous operation mode. Errors are reported,  but  ldapsearch
52              will  continue  with  searches. The default is to exit after re‐
53              porting an error.  Only useful in conjunction with -f.
54
55       -u     Include the User Friendly Name form of  the  Distinguished  Name
56              (DN) in the output.
57
58       -t[t]  A  single  -t  writes retrieved non-printable values to a set of
59              temporary files.  This is useful for dealing  with  values  con‐
60              taining  non-character data such as jpegPhoto or audio. A second
61              -t writes all retrieved values to files.
62
63       -T path
64              Write temporary files to directory specified by  path  (default:
65              system default tmp directory). The environment variables TMPDIR,
66              TMP, or TEMP will override the default path.
67
68       -F prefix
69              URL prefix for temporary files.  Default  is  file://path  where
70              path  is the system default tmp directory or the value specified
71              with -T.
72
73       -A     Retrieve attributes only (no values).  This is useful  when  you
74              just  want to see if an attribute is present in an entry and are
75              not interested in the specific values.
76
77       -L     Search results are display in LDAP Data Interchange  Format  de‐
78              tailed in ldif(5).  A single -L restricts the output to LDIFv1.
79               A second -L disables comments.  A third -L disables printing of
80              the LDIF version.  The default is to use an extended version  of
81              LDIF.
82
83       -S attribute
84              Sort the entries returned based on attribute. The default is not
85              to sort entries returned.  If attribute is a zero-length  string
86              (""),  the entries are sorted by the components of their Distin‐
87              guished Name.  See ldap_sort(3)  for  more  details.  Note  that
88              ldapsearch  normally prints out entries as it receives them. The
89              use of the -S option defeats this behavior, causing all  entries
90              to be retrieved, then sorted, then printed.
91
92       -b searchbase
93              Use  searchbase  as the starting point for the search instead of
94              the default.
95
96       -s {base|one|sub|children}
97              Specify the scope of the search to be one of base, one, sub,  or
98              children  to specify a base object, one-level, subtree, or chil‐
99              dren search.  The default is sub.  Note: children scope requires
100              LDAPv3 subordinate feature extension.
101
102       -a {never|always|search|find}
103              Specify  how  aliases  dereferencing  is done.  Should be one of
104              never, always, search, or find to specify that aliases are never
105              dereferenced,  always dereferenced, dereferenced when searching,
106              or dereferenced only when  locating  the  base  object  for  the
107              search.  The default is to never dereference aliases.
108
109       -l timelimit
110              wait  at  most  timelimit  seconds  for a search to complete.  A
111              timelimit of 0 (zero) or none means no limit.   A  timelimit  of
112              max  means  the  maximum  integer  allowable by the protocol.  A
113              server may impose a maximal timelimit which only the  root  user
114              may override.
115
116       -z sizelimit
117              retrieve at most sizelimit entries for a search.  A sizelimit of
118              0 (zero) or none means no limit.  A sizelimit of max  means  the
119              maximum  integer allowable by the protocol.  A server may impose
120              a maximal sizelimit which only the root user may override.
121
122       -f file
123              Read a series of lines from file, performing one LDAP search for
124              each  line.   In this case, the filter given on the command line
125              is treated as a pattern where the first and only  occurrence  of
126              %s  is  replaced with a line from file.  Any other occurrence of
127              the the % character in the pattern will be regarded as an error.
128              Where  it  is desired that the search filter include a % charac‐
129              ter, the character should be encoded as \25 (see RFC 4515).   If
130              file is a single - character, then the lines are read from stan‐
131              dard input.  ldapsearch will exit when the first  non-successful
132              search result is returned, unless -c is used.
133
134       -M[M]  Enable manage DSA IT control.  -MM makes control critical.
135
136       -x     Use simple authentication instead of SASL.
137
138       -D binddn
139              Use the Distinguished Name binddn to bind to the LDAP directory.
140              For SASL binds, the server is expected to ignore this value.
141
142       -W     Prompt for simple authentication.  This is used instead of spec‐
143              ifying the password on the command line.
144
145       -w passwd
146              Use passwd as the password for simple authentication.
147
148       -y passwdfile
149              Use  complete  contents of passwdfile as the password for simple
150              authentication.
151
152       -H ldapuri
153              Specify URI(s) referring to the ldap server(s); a list  of  URI,
154              separated  by  whitespace or commas is expected; only the proto‐
155              col/host/port fields  are  allowed.   As  an  exception,  if  no
156              host/port  is  specified, but a DN is, the DN is used to look up
157              the corresponding host(s) using the DNS SRV  records,  according
158              to  RFC 2782.  The DN must be a non-empty sequence of AVAs whose
159              attribute type is "dc" (domain component), and must  be  escaped
160              according to RFC 2396.
161
162       -P {2|3}
163              Specify the LDAP protocol version to use.
164
165       -e [!]ext[=extparam]
166
167       -E [!]ext[=extparam]
168
169              Specify  general  extensions  with -e and search extensions with
170              -E.  ´!´ indicates criticality.
171
172              General extensions:
173                [!]assert=<filter>    (an RFC 4515 Filter)
174                !authzid=<authzid>    ("dn:<dn>" or "u:<user>")
175                [!]bauthzid           (RFC 3829 authzid control)
176                [!]chaining[=<resolve>[/<cont>]]
177                [!]manageDSAit
178                [!]noop
179                ppolicy
180                [!]postread[=<attrs>] (a comma-separated attribute list)
181                [!]preread[=<attrs>]  (a comma-separated attribute list)
182                [!]relax
183                sessiontracking[=<username>]
184                abandon,cancel,ignore (SIGINT sends abandon/cancel,
185                or ignores response; if critical, doesn't wait for SIGINT.
186                not really controls)
187
188              Search extensions:
189                !dontUseCopy
190                [!]domainScope                       (domain scope)
191                [!]mv=<filter>                       (matched values filter)
192                [!]pr=<size>[/prompt|noprompt]       (paged results/prompt)
193                [!]sss=[-]<attr[:OID]>[/[-]<attr[:OID]>...]  (server side sorting)
194                [!]subentries[=true|false]           (subentries)
195                [!]sync=ro[/<cookie>]                (LDAP Sync refreshOnly)
196                        rp[/<cookie>][/<slimit>]     (LDAP Sync refreshAndPersist)
197                [!]vlv=<before>/<after>(/<offset>/<count>|:<value>)  (virtual list view)
198                [!]deref=derefAttr:attr[,attr[...]][;derefAttr:attr[,attr[...]]]
199                [!]<oid>[=:<value>|::<b64value>]
200
201       -o opt[=optparam]
202
203              Specify any ldap.conf(5) option or one of the following:
204                nettimeout=<timeout>  (in seconds, or "none" or "max")
205                ldif_wrap=<width>     (in columns, or "no" for no wrapping)
206
207
208       -O security-properties
209              Specify SASL security properties.
210
211       -I     Enable SASL Interactive mode.  Always  prompt.   Default  is  to
212              prompt only as needed.
213
214       -Q     Enable SASL Quiet mode.  Never prompt.
215
216       -N     Do not use reverse DNS to canonicalize SASL host name.
217
218       -U authcid
219              Specify  the authentication ID for SASL bind. The form of the ID
220              depends on the actual SASL mechanism used.
221
222       -R realm
223              Specify the realm of authentication ID for SASL bind.  The  form
224              of the realm depends on the actual SASL mechanism used.
225
226       -X authzid
227              Specify  the  requested authorization ID for SASL bind.  authzid
228              must be one of the following formats: dn:<distinguished name> or
229              u:<username>
230
231       -Y mech
232              Specify  the  SASL  mechanism  to be used for authentication. If
233              it's not specified, the program will choose the  best  mechanism
234              the server knows.
235
236       -Z[Z]  Issue StartTLS (Transport Layer Security) extended operation. If
237              you use -ZZ, the command will require the operation to  be  suc‐
238              cessful.
239

OUTPUT FORMAT

241       If  one  or  more  entries are found, each entry is written to standard
242       output in LDAP Data Interchange Format or ldif(5):
243
244           version: 1
245
246           # bjensen, example, net
247           dn: uid=bjensen,dc=example,dc=net
248           objectClass: person
249           objectClass: dcObject
250           uid: bjensen
251           cn: Barbara Jensen
252           sn: Jensen
253           ...
254
255       If the -t option is used, the URI of a temporary file is used in  place
256       of  the  actual value.  If the -A option is given, only the "attribute‐
257       name" part is written.
258

EXAMPLE

260       The following command:
261
262           ldapsearch -LLL "(sn=smith)" cn sn telephoneNumber
263
264       will perform a subtree search (using the default search base and  other
265       parameters  defined in ldap.conf(5)) for entries with a surname (sn) of
266       smith.  The common name (cn), surname (sn) and  telephoneNumber  values
267       will  be  retrieved  and  printed to standard output.  The output might
268       look something like this if two entries are found:
269
270           dn: uid=jts,dc=example,dc=com
271           cn: John Smith
272           cn: John T. Smith
273           sn: Smith
274           sn;lang-en: Smith
275           sn;lang-de: Schmidt
276           telephoneNumber: 1 555 123-4567
277
278           dn: uid=sss,dc=example,dc=com
279           cn: Steve Smith
280           cn: Steve S. Smith
281           sn: Smith
282           sn;lang-en: Smith
283           sn;lang-de: Schmidt
284           telephoneNumber: 1 555 765-4321
285
286       The command:
287
288           ldapsearch -LLL -u -t "(uid=xyz)" jpegPhoto audio
289
290       will perform a subtree search using the default search base for entries
291       with  user  id of "xyz".  The user friendly form of the entry's DN will
292       be output after the line that contains the DN itself, and the jpegPhoto
293       and audio values will be retrieved and written to temporary files.  The
294       output might look like this if one entry with one value for each of the
295       requested attributes is found:
296
297           dn: uid=xyz,dc=example,dc=com
298           ufn: xyz, example, com
299           audio:< file:///tmp/ldapsearch-audio-a19924
300           jpegPhoto:< file:///tmp/ldapsearch-jpegPhoto-a19924
301
302       This command:
303
304           ldapsearch -LLL -s one -b "c=US" "(o=University*)" o description
305
306       will perform a one-level search at the c=US level for all entries whose
307       organization name (o) begins with University.   The  organization  name
308       and description attribute values will be retrieved and printed to stan‐
309       dard output, resulting in output similar to this:
310
311           dn: o=University of Alaska Fairbanks,c=US
312           o: University of Alaska Fairbanks
313           description: Naturally Inspiring
314           description: leaf node only
315
316           dn: o=University of Colorado at Boulder,c=US
317           o: University of Colorado at Boulder
318           description: No personnel information
319           description: Institution of education and research
320
321           dn: o=University of Colorado at Denver,c=US
322           o: University of Colorado at Denver
323           o: UCD
324           o: CU/Denver
325           o: CU-Denver
326           description: Institute for Higher Learning and Research
327
328           dn: o=University of Florida,c=US
329           o: University of Florida
330           o: UFl
331           description: Warper of young minds
332
333           ...
334

DIAGNOSTICS

336       Exit status is zero if no errors occur.  Errors result  in  a  non-zero
337       exit status and a diagnostic message being written to standard error.
338

SEE ALSO

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

AUTHOR

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

ACKNOWLEDGEMENTS

347       OpenLDAP Software is developed and maintained by The  OpenLDAP  Project
348       <http://www.openldap.org/>.  OpenLDAP Software is derived from the Uni‐
349       versity of Michigan LDAP 3.3 Release.
350
351
352
353OpenLDAP 2.6.2                    2022/05/04                     LDAPSEARCH(1)
Impressum