Shell: How to list directories recursively down to depth n?

Can someone who is familiar with shell commands tell me how to obtain a list of a directory and its subdirectories down to depth n (and at best while EXcluding files; I’m interested only in the directory structure).

Concretely, I want to get an overview of my music library folder. It’s general structure is /Music library/<artist name>/<album name>/<title name.mp3>, and I’d like to print out a list of the folders it contains.

Cheers

find dir -type d -maxdepth n

0 means just the named director(ies), 1 means include 1 level below, and so on.

Thanks! :slight_smile:

To be nasty.

You got the exact answer you asked for, but why the max depth? The whole music library only has directories two levels down as you say yourself, so output with or without the -maxdepth will be the same. :wink:

BTW studying the possibilities of man find will give you a wealth of methods to do things like this.

Because the music library has 3 levels, and if I print out everything down to the very last, I end up with endless pages of title names, which I don’t need at all.
Filtering the result to get rid of file names prolly would’ve been another option, and I experimented with it a bit, but it didn’t work the way I wanted it to.

Frankly, I hate MAN pages. More complex commands like find have descriptions that are rather long and fantastically tedious to read. A lot of commands have rather nice explanations on the internet, but it’s difficult to google for ‘find’ given the widespread use of the word.

That’s fine, I’m completely zen … :wink:

Though I am sure you got the point, I will nevertheless protest (staying nasty >:) ). You third level (the title names) are files (mp3) and not directories. Thus the *-type d *is the crucial option to your quest, not the -maxdepth 2.

You should get good results with keywords like “linux find command” or even “find command.”

A good source for bash commands on the Web is SS64 at

Basically man pages, but in readable format.

But I prefer the readabilaty of man:find (and other man: pages) in Konqueror.

Nice feature. I’ll have to check that out.

Thanks for the links & tips, guys.

I’m not sure I got the point, but I’ll definitely look into the issue. Could you please type up and executive summary and leave 2 copies with my secretary? Oh, and another copy goes to Mr. Barnes in accounting.

There’s a nice looking add-on for Firefox Called “FireMan” that adds this functionality. Unfortunately, it’s only available for FF 3.0 and earlier.

https://addons.mozilla.org/en-US/firefox/addon/8709

> But I prefer the readabilaty of -man:find- (and other -man:- pages) in
> Konqueror.

i use it all the time…but, type less…try, in the address bar:

#find :slight_smile:


brassy

Oops, that is 3 characters less for every man page, thanks for this.

> Oops, that is 3 characters less for every man page, thanks for this.

adds up, over a life time…young feller…

but, if you think it is of no value to you…you are welcome anyway.


brassy

Not so young any more. But my thanks are sincere! I certainly will try to switch over to your method. The more because I mostly type man tool instead of man:tool in the title bar, which gives me an error window I have to click and a click back to the title bar and typing to correct. So the gain is in practice much more to me old fellow.

:wink:


brassy