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

NAME

6       ldapsearch - LDAP search tool
7

SYNOPSIS

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

OUTPUT FORMAT

227       If  one  or  more  entries are found, each entry is written to standard
228       output in LDAP Data Interchange Format or ldif(5):
229
230           version: 1
231
232           # bjensen, example, net
233           dn: uid=bjensen,dc=example,dc=net
234           objectClass: person
235           objectClass: dcObject
236           uid: bjensen
237           cn: Barbara Jensen
238           sn: Jensen
239           ...
240
241       If the -t option is used, the URI of a temporary file is used in  place
242       of  the  actual value.  If the -A option is given, only the "attribute‐
243       name" part is written.
244

EXAMPLE

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

DIAGNOSTICS

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

SEE ALSO

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

AUTHOR

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

ACKNOWLEDGEMENTS

333       OpenLDAP Software is developed and maintained by The  OpenLDAP  Project
334       <http://www.openldap.org/>.   OpenLDAP Software is derived from Univer‐
335       sity of Michigan LDAP 3.3 Release.
336
337
338
339OpenLDAP 2.4.23                   2010/06/30                     LDAPSEARCH(1)
Impressum