Page 1 of 2 12 LastLast
Results 1 to 10 of 16

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

  1. #1

    Default 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

  2. #2
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: Shell: How to list directories recursively down to depth

    find dir -type d -maxdepth n

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

  3. #3

    Default Re: Shell: How to list directories recursively down to depth

    Thanks!

  4. #4
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,157

    Default Re: Shell: How to list directories recursively down to depth

    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.

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

  5. #5

    Default Re: Shell: How to list directories recursively down to depth

    Quote Originally Posted by hcvv View Post
    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.
    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.

    Quote Originally Posted by hcvv View Post
    BTW studying the possibilities of man find will give you a wealth of methods to do things like this.
    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.

    Quote Originally Posted by hcvv View Post
    To be nasty.
    That's fine, I'm completely zen ...

  6. #6
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,157

    Default Re: Shell: How to list directories recursively down to depth

    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.
    Henk van Velden

  7. #7
    Join Date
    Aug 2008
    Location
    Seattle, WA
    Posts
    1,376

    Default Re: Shell: How to list directories recursively down to depth

    Quote Originally Posted by homoludens1000 View Post
    it's difficult to google for 'find' given the widespread use of the word.
    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

    http://ss64.com/bash/

    Basically man pages, but in readable format.

  8. #8
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,157

    Default Re: Shell: How to list directories recursively down to depth

    Quote Originally Posted by chief_sealth View Post
    A good source for bash commands on the Web is SS64 at

    bash commands - Linux MAN Pages

    Basically man pages, but in readable format.
    But I prefer the readabilaty of man:find (and other man: pages) in Konqueror.
    Henk van Velden

  9. #9
    Join Date
    Aug 2008
    Location
    Seattle, WA
    Posts
    1,376

    Default Re: Shell: How to list directories recursively down to depth

    Quote Originally Posted by hcvv View Post
    But I prefer the readabilaty of man:find (and other man: pages) in Konqueror.
    Nice feature. I'll have to check that out.

  10. #10

    Default Re: Shell: How to list directories recursively down to depth

    Thanks for the links & tips, guys.

    Quote Originally Posted by hcvv View Post
    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.
    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.

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •