Search code examples
shellldapshdistinguishedname

Make LDAP search don't show DN


How would I make a bourne shell code for a LDAP search to not return DN and return only CN? I am using iTerm2 for this.


Solution

  • If you only want to see the cn results, then you can use something like:

    ldapsearch -o ldif-wrap=no -L <blah> cn | grep '^cn:'
    

    where <blah> is your bind/search conditions

    the reason it returns the dn is because the returned data would not be properly formed ldif without it.

    By using -o ldif-wrap=no you don't have to cope with issues involving line-wrapping of the returned data.