Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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