I'm looking to get the name of a bunch a directories at a specified level.

This is what I've got so far:

find . -type d -depth 2 -print 

But this also prints the relative path of these directories. How can I just get their name?

find . -type d -depth 2 -printf '%f\n'

From the GNU findutils manual:

%f File's name with any leading directories removed (only the last element).

Edit: In the lack of the -printf action, try this:

find . -type d -depth 2 -exec basename '{}' ';'
  • Just forgot to say that i'm on Mac OSX. find doesn't have -printf option. – Matthieu Riegler Jan 2 '13 at 0:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.