Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 2 down vote accepted
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 '{}' ';'
share|improve this answer
Just forgot to say that i'm on Mac OSX. find doesn't have -printf option. – Matthieu Riegler Jan 2 '13 at 0:06
Perfect thanks ! – Matthieu Riegler Jan 2 '13 at 0:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .