How do I remove all entries from LDAP?
1 answer
ldapdelete
is to remove a specific DN, you cannot use wilcard.
No native "oneliner". You can execute ldapsearch
and provide the DN list resulting from this search inldapdelete
Something like:
ldapsearch -LLL -s one -b "dc=domain,dc=com" "(cn=*)" dn | awk -F": " '$1~/^\s*dn/{print $2}' > listOfDNtoRemove.txt && ldapdelete -r -f listOfDNtoRemove.txt
-
-s one
: this parameter inldapsearch
should only fetch the first level child of the branchdc=domain,dc=com
-
-LLL
: this parameter must be in output formatLDIF
-
-r
: this option is for recursively deleting the found first-level branch and their children -
awk -F": " '$1~/^\s*dn/{print $2}'
: this oneawk
should only print the line starting withdn:
and print the valuedn
NOTE. ldapdelete
also reads a list of DNs from standard input, so you can directly pipe the results ldapsearch
to ldapdelete
if you want to avoid the temporary file
+1
source to share