OpenLDAP---ldapsearch use

Source: Internet
Author: User
Tags ldap ldapsearch openldap

ldapsearch Tables
The following table describes the difference between uppercase and lowercase parameters that can be used for ldapsearch.

Number of references Use
-? Print help on using Ldapsearch.
-A Deref Specifies the alias reverse reference. Please enter never, always, search, or find. Assuming this parameter is not used, the default is never.
-A Retrieves only the name of the property, not the value of the property.
-B Base DN Specifies the distinguished name to use as the starting point for the search. Use an argument to specify the value, for example: "Ou=west,o=acme,c=us"

You must use this parameter if the server you are searching for needs to specify a starting point for the search. Otherwise, this number of parameters is optional.

You can also use-B and-S to determine the search scope at the same time. Without –s,-b, the item specified as the starting point and all children of the item are searched.

-B Agree to print non-ASCII values
-D bind DN Specifies that the server is used to verify your distinguished name. The name must match the items in the folder, and you must have the permissions required to search for the folder.

Use an argument to specify the name, for example: "Cn=directory manager,o=acme,c=us"

Assuming that this parameter is not used, the connection to the server is anonymous. Assuming that the server does not agree to anonymous connections, you must use-D.

In addition to-D, you must also use the-w parameter to specify the password associated with the distinguished name.

-F File Specifies the file that includes the search filter that you want to use, such as the-f filter. Please put each search filter on a separate line. Ldapsearch will run a search for each row. You can choose to specify the filtering mode. For example, specify-F to filter "cn=%s" and enter a value for the common name in each line of the file.
-F Sep Print Sep instead of an equal sign (=) between the property name and the value. For example, assume that a tool that reads the Ldapsearch output can use this parameter when it wants to use a different delimiter.
-H Host Name Specifies the hostname of the server to which you want to connect, such as-H
-L TimeLimit Specifies the time limit (in seconds) for the search to complete. If you do not specify this parameter or specify a limit of 0, the search does not have a time limit. However, Ldapsearch's wait time will never exceed the search time limit set on the server.
-L Specifies output in LDIF format. The LDIF format uses colons (:) Instead of an equal sign (=) as an attribute descriptive descriptor. LDIF is useful for adding or changing a large number of folder items at once. For example, the ability to import the output into a folder that is compatible with LDAP.
-M The reference object is managed as a normal item so that Ldapsearch can return the properties of the entry itself, rather than the attributes of the item being tested.
-N Shows how to run the search, but does not actually run the search
-P Port Specifies the port used by the server. Assuming this parameter is not used, Ldapsearch uses 389 port by default.
-R Do not voluntarily follow the search references returned by the server. Note that the Netscape folder server uses the term referrals for the search reference.
-S scope Specify the search scope when using the-B parameter:
  • Base-searches only the items specified by the-b parameter
  • OneLevel--searches only for the direct subkeys of the-b parameter specified, not the item itself
  • Subtree--Searches for the specified item of the-B parameter and all its subkeys. This is the default behavior for use-B when not with-S.
It is not important to specify the order of-B and-S.
-S attribute Sorts the results by the specified attributes.
-Z SizeLimit Specifies the maximum number of returned items. Assuming that this parameter is not specified or the specified limit is 0, the returned item has no number limit. However, Ldapsearch will never return more items than the server agrees.
-U Specifies that Ldapsearch returns the distinguished name in a user-friendly format.
-V Specifies that Ldapsearch is executed in verbose mode.
-W Password Specifies the password associated with the distinguished name used with the-D parameter.
X When used with-s, you can specify that the LDAP server sort the results before returning them. Assume that using-s instead of using –x,ldapsearch will sort the results.

table of operators used in the Ldapsearch search filter
The following table describes the operators that can be used in search filters.

Operator Use Example
= Find items that include the same property value as the specified value "Cn=john Browning"
= <string>*<string> Finds the same item as the specified substring in the included property value "Cn=john*"


>= Finds a specific item that contains a number or alphabetic value of a property that is greater than or equal to the specified value. "Cn>=d"
<= Finds a specific item that contains a number or alphabetic value of a property that is less than or equal to the specified value. "Roomnumber<=300"
=* Finds the item that includes the value of a particular property, without the value of the Tube property. "Sn=*"
~= Finds a specific item in which the value of the property contained is approximately equal to the specified value. "Sn~=brning" may return sn=browning
& Find items that match the criteria specified in all search filters (& (Cn=john Browning) (L=dallas))
| Finds items that match the criteria specified in at least one search filter "(| (Cn=john Browning) (L=dallas)) "
! Find items that do not match any of the criteria specified in the search filter "(! (Cn=john Browning) (L=dallas)) "

Search filters using Ldapsearch
You must use the search filter to specify the properties to search for. The syntax for the search filter is:

      "<attribute> <operator> <value>"

For example, the following search filter can find all of the specific items, with only the value of Smith as the SN (alternative) attribute in the item:


The ability to specify discretionary properties stored in a folder in a search filter. The following are common properties for searching for personal items:

    • CN--The public name of the individual
    • sn--The surname of the individual
    • Telephonenumber--A personal phone number
    • L--Personal location

You can specify a search filter on the Ldapsearch command line, or specify them in the file, and use the Lsearch parameter-F to reference the file. If you are using a file, specify each search filter in a separate row.

Note: Suppose LDAP folders (such as the Domino LDAP folder) Support language tags, you can include them in search filters. Like what:


Multiple search filters using Boolean operators

You can use multiple search filters and Boolean operators. Use the following syntax:

      "(operator (filter))"

For example, use the following search filter to find items that are not known as Browning, and where the location is Dallas.

      (& (Sn=browning) (L=dallas))

Boolean operators can be nested. For example, use the following search filter to find items in the Mail network domain MDN that surname is Caneel or givenname as Alfred:

      ( & (MAILDOMAIN=MDN) (| ( Sn=caneel) (givenname=alfred))) "

Examples of using Ldapsearch

The following table provides examples of useful programs that use Ldapsearch.

Search Command
All entries on the host of port 389 are used, and all properties and values are returned Ldapsearch-h "objectclass=*"
Same as above, but only property names are returned Ldapsearch-a-H "objectclass=*"
All entries on the host of port 389 are used, and all aliases found are referenced in reverse Ldapsearch-a always-h "objectclass=*"
Use all entries on the host of port 389 and return properties such as Mail, CN, SN, and givenname Ldapsearch-h "objectclass=*" Mail cn sn givenname
On host using port 389, search (cn=mike*) under the "Ou=west,o=acme,c=us" Datum and return all properties and values Ldapsearch-b "Ou=west,o=acme,c=us"-H "(cn=mike*)"
Use a level on the host of port 389 and return all properties and values Ldapsearch-s onelevel-h "objectclass=*"
Ibid., but limits the scope of the benchmark Ldapsearch-s base-h "objectclass=*"
Use all entries on the host of port 389 and return all properties and values; Search time is limited to five seconds Ldapsearch-l 5-h "objectclass=*"
Use all entries on the host of port 389 and return all properties and values; limit size to five Ldapsearch-z 5-h "objectclass=*"
Using all the entries on the host of port 389, the bundle is: User "Cn=john doe,o=acme", password "password", and return all properties and values in LDIF format Ldapsearch-h "Cn=john doe,o=acme"-W password-l "objectclass=*"
Use the host for port 389. For the "Cn=john Doe,o=acme" entry, return all properties that it agrees to view anonymously Ldapsearch-h "-S Base-b" Cn=john doe,o=acme "objectclass=*"
Configuration to listen for LDAP requests on Port 391 also has all the items on a host Ldapsearch-h 391 "objectclass=*" on Port 391. Subtree Search (default) for any of the properties that match any of the attributes in the or filter, starting with the organization "O=IBM". The timeout value is 300 seconds, and the maximum number of items returned is set to 1000. Only the DN (default) and CN (which is the common filter for WEB applications) are returned. Ldapsearch-h 391-b "O=IBM"-L 300-z (& (Objectclass=person) (| ( Cn=jerry seinfeld*) (givenname=jerryseinfeld*) (Sn=jerry seinfeld*) (Mail=jerry seinfeld*))) "CN on Port 391. Starting with the Datum "Cn=hr group,ou=asia,o=ibm", the time limit is 300 seconds, and all members of this item are queried. (There is also a common filter used by the WEB application to determine the membership of the group.) Ldapsearch-h 391-b "Cn=hr group,ou=asia,o=ibm"-S Base-l "(objectclass=*)" member

OpenLDAP---ldapsearch use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.