3.2. Managing Entries from the Command Line
Note
3.2.1. Providing Input from the Command Line
ldapmodify and ldapdelete utilities directly from the command line, you must use LDIF statements. For detailed information on LDIF statements, see Section 3.3, “Using LDIF Update Statements to Create or Modify Entries”.
ldapmodify and ldapdelete utilities read the statements that you enter in exactly the same way as if they were read from a file. When all of the input has been entered, enter the character that the shell recognizes as the end of file (EOF) escape sequence. The utility then begins operations based on the supplied inputs.
^D).
ldapmodify:
ldapmodify -D "cn=directory manager" -W -p 389 -h server.example.com -x dn: cn=Barry Nixon,ou=people,dc=example,dc=com changetype: modify delete: telephonenumber - add: manager manager: cn=Harry Cruise,ou=people,dc=example,dc=com ^D
People subtree, create an entry representing that subtree before creating entries within the subtree. For example:
dn: dc=example,dc=com dn: ou=People,dc=example,dc=com ...People subtree entries. ... dn: ou=Group,dc=example,dc=com ...Group subtree entries. ...
3.2.2. Creating a Root Entry from the Command Line
ldapmodify command-line utility can be used to create a new root entry in a database. For example:
ldapmodify -a -D "cn=directory manager" -W -p 389 -h server.example.com -x
dn: Suffix_Name
changetype: add
objectclass: newobjectclassNote
ldapmodify to add root objects only if you have one database per suffix. If you create a suffix that is stored in several databases, you must use the ldif2db utility with the -noption parameter to specify the database that will hold the new entries. For information, see Section 4.1.6, “Importing from the Command Line”.
3.2.3. Adding Entries Using LDIF
- Define the entries in an LDIF file.LDIF files are described in Appendix B, LDAP Data Interchange Format.
- Import the LDIF file from the Directory Server Console.See Section 4.1.4, “Importing a Database from the Console” for information about LDIF file formats. When you import the LDIF file, select Append to database in the Import dialog box so that the server will only import entries that do not currently exist in the directory.
ldapmodify command with the -f option.
3.2.4. Adding and Modifying Entries Using ldapmodify
ldapmodify command can add and modify entries in an existing Directory Server database. The ldapmodify command opens a connection to the specified server using the supplied distinguished name and password and modifies the entries based on LDIF update statements contained in a specified file. Because ldapmodify uses LDIF update statements, ldapmodify can do everything that ldapdelete can do.
ldapmodify:
- If the server detects an attribute or object class in the entry that is not known to the server, then the modify operation will fail when it reaches the erroneous entry. All entries that were processed before the error was encountered will be successfully added or modified. If you run
ldapmodifywith the-coption (do not stop on errors), all correct entries processed after the erroneous entry will be successfully added or modified. - If a required attribute is not present, the modify operation fails. This happens even if the offending object class or attribute is not being modified.
Note
dc=example,dc=com) using ldapmodify, you must bind to the directory as the Directory Manager.
3.2.4.1. Adding Entries Using ldapmodify
ldapmodify, pass the -a option to indicate an add operation and the LDIF file to use which contains the new entry information (and, optionally, the bind credentials and any connection information). For example:
ldapmodify -a -D "cn=directory manager" -W -p 389 -h server.example.com -x -f new.ldifnew.ldif. (In this example, the LDIF statements in the new.ldif file do not specify a change type. They follow the format defined in Section B.1, “About the LDIF File Format”.)
ldapmodify utility waits for the DN of the new entry and then each object class and attribute for the entry, each on a new line in LDIF format. When the last attribute is entered, hit enter twice to submit the new entry.
ldapmodify parameters used in the example.
Table 3.2. ldapmodify Parameters Used for Adding Entries
| Parameter Name | Description |
|---|---|
| -a | Specifies that the modify operation will add new entries to the directory. |
| -D | Specifies the distinguished name with which to authenticate to the server. The value must be a DN recognized by the Directory Server, and it must also have the authority to modify the entries. |
| -w | Specifies the password associated with the distinguished name specified in the -D parameter. |
| -h | Specifies the name of the host on which the server is running. |
| -p | Specifies the port number that the server uses. |
| -f | Optional parameter that specifies the file containing the LDIF update statements used to define the modifications. If you do not supply this parameter, the update statements are read from stdin. For information on supplying LDIF update statements from the command line, see Section 3.2.1, “Providing Input from the Command Line”. |
3.2.4.2. Modifying Entries Using ldapmodify
ldapmodify, specify the DN and password to bind to the Directory Server, the port and host of the Directory Server, and the LDIF file to use, as when adding entries with ldapmodify. For example:
ldapmodify -D "cn=directory manager" -W -p 389 -h server.example.com -x -f modify_statements
modify_statements. Before the entries can be modified, you must first create the modify_statements file with the appropriate LDIF update statements; LDIF update statements are described in Section 3.3, “Using LDIF Update Statements to Create or Modify Entries”.
ldapmodify parameters used in the example.
Table 3.3. ldapmodify Parameters Used for Modifying Entries
| Parameter Name | Description |
|---|---|
| -D | Specifies the distinguished name with which to authenticate to the server. The value must be a DN recognized by the Directory Server, and it must also have the authority to modify the entries. |
| -w | Specifies the password associated with the distinguished name specified in the -D parameter. |
| -h | Specifies the name of the host on which the server is running. |
| -p | Specifies the port number that the server uses. |
| -f | Optional parameter that specifies the file containing the LDIF update statements used to define the modifications. If you do not supply this parameter, the update statements are read from stdin. For information on supplying LDIF update statements from the command line, see Section 3.2.1, “Providing Input from the Command Line”. |
| -x | Disables SASL to allow a simple bind to the server. |
3.2.5. Deleting Entries Using ldapdelete
ldapdelete command-line utility opens a connection to the specified server using the provided distinguished name and password and deletes the specified entry or entries.
Note
ou=People,dc=example,dc=com cn=Paula Simon,ou=People,dc=example,dc=com cn=Jerry O'Connor,ou=People,dc=example,dc=com
People subtree can be deleted only if there are not any entries below it. To delete ou=People,dc=example,dc=com, you must first delete Paula Simon and Jerry O'Connor's entries and all other entries in that subtree.
ldapmodify, running ldapdelete requires the DN and password to bind to the Directory Server, the port and host of the Directory Server, and the DNs of the entries to delete. For example:
ldapdelete -D "cn=directory manager" -w secret -p 389 -h server.example.com -x "cn=Robert Jenkins,ou=People,dc=example,dc=com" "cn=Lisa Jangles,ou=People,dc=example,dc=com"
cn=Robert Jenkins,ou=People,dc=example,dc=com and cn=Lisa Jangles,ou=People,dc=example,dc=com) are appended to the end of the delete command.
ldapdelete parameters used in the example:
Table 3.4. ldapdelete Parameters Used for Deleting Entries
| Parameter Name | Description |
|---|---|
| -D | Specifies the distinguished name with which to authenticate to the server. The value must be a DN recognized by the Directory Server, and it must also have the authority to modify the entries. |
| -w | Specifies the password associated with the distinguished name specified in the -D parameter. |
| -h | Specifies the name of the host on which the server is running. |
| -p | Specifies the port number that the server uses. |
| -x | Disables SASL to allow a simple bind to the server. |
3.2.6. Using Special Characters
*), or backslash (\). When this situation occurs, enclose the value in quotation marks (""). For example:
-D "cn=Barbara Jensen,ou=Product Development,dc=example,dc=com"
\). For example:
-D "cn=Patricia Fuentes,ou=people,o=example.com Bolivia\,S.A."
example.com Bolivia, S.A. tree, use the following command:
ldapdelete -D "cn=directory manager" -w secret -p 389 -h server.example.com -x "cn=Patricia Fuentes,ou=People,o=example.com Bolivia\,S.A."

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.