10.2. Using the ldapsearch filters
The ldapsearch filters allow you to narrow down the search results.
For example, you want the search result to contain all the entries with a common names set to example:
"(cn=example)"
In this case, the equal sign (=) is the operator, and example is the value.
| Search type | Operator | Description |
|---|---|---|
| Equality | = | Returns the entries with the exact match to the value. For example, cn=example. |
| Substring | =string* string | Returns all entries with the substring match. For example, cn=exa*l. The asterisk (*) indicates zero (0) or more characters. |
| Greater than or equal to | >= | Returns all entries with attributes that are greater than or equal to the value. For example, uidNumber >= 5000. |
| Less than or equal to | <= | Returns all entries with attributes that are less than or equal to the value. For example, uidNumber <= 5000. |
| Presence | =* | Returns all entries with one or more attributes. For example, cn=*. |
| Approximate | ~= | Returns all entries with the similar to the value attributes. For example, l~=san fransico can return l=san francisco. |
You can use boolean operators to combine multiple filters to the ldapsearch command.
| Search type | Operator | Description |
|---|---|---|
| AND | & | Returns all entries where all statements in the filters are true. For example, (&(filter)(filter)(filter)…). |
| OR | | | Returns all entries where at least one statement in the filters is true. For example, (|(filter)(filter)(filter)…). |
| NOT | ! | Returns all entries where the statement in the filter is not true. For example, (!(filter)). |