List all folders in Music folder with Terminal?

Discussion in 'macOS' started by bsheridan, Aug 5, 2008.

  1. bsheridan macrumors 6502

    bsheridan

    Joined:
    Jan 11, 2008
    #1
    I'm not experienced with Terminal but know what the basic commands do ls,cd, rm etc.
    I'm trying to get a list of all the music album folders that are located in my music folder under each artist. (kind of a hierarchy I guess)
    ~/Music/iTunes/iTunes Music contains all my artist folders

    In terminal, it says 'No such file or directory' for the 'iTunes Music' folder, so I'm not sure what to do next.
    Is there a better way to do what I'm trying to do?

    any help would be appreciated, b.
     
  2. ergdegdeg Moderator emeritus

    ergdegdeg

    Joined:
    Oct 13, 2007
    #2
    The problem is that there is a <space> in "iTunes Music". In Terminal you have to type iTunes\ Music.
     
  3. markjewiss macrumors member

    Joined:
    Feb 8, 2007
    Location:
    Dunmow, UK
    #3
    You just want to see *folders* within the iTunes Music folder?

    Try this:

    * launch terminal
    * ls -l ~/Music/iTunes/iTunes\ Music | grep drwx

    That'll give you a list of all the directories, and exclude any individual files. If you want to search through all of the directories that this returns as well, then the easiest way to do it (that I know of) is to script something. What are you trying to do?

    MJ.
     
  4. bsheridan thread starter macrumors 6502

    bsheridan

    Joined:
    Jan 11, 2008
    #4
    Thanks for your help. I now have a list of all my artist folders. Is there any way to list all the folders in all the artist folders?
    eg.
    Arcade Fire -
    • Funeral
    • Neon Bible
    Arctic Monkeys -
    • Favourite Worst Nightmare
    Beck -
    • Guero
    etc.
     
  5. ergdegdeg Moderator emeritus

    ergdegdeg

    Joined:
    Oct 13, 2007
  6. bsheridan thread starter macrumors 6502

    bsheridan

    Joined:
    Jan 11, 2008
    #6
    Found what I was looking for on google after ergdegdeg's capital R tip.

    Go to whichever folder and paste
    Code:
    ls -R | grep ":" | sed -e 's/://' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'
    Obtained from this link

    thanks again guys, b.
     
  7. Benway macrumors newbie

    Joined:
    Oct 20, 2010
    #7
    Thanks a lot, but I might need a bit of help to get this command to work.

    Hi! Thanks a lot for the tips, but I'm trying to make it work.

    Like you, I want to have a list of all the folders and all of their subfolders within a main folder [but NOT the individual files within. Just the folders and all subfolders]

    However, when I drag my main "music" folder to terminal, and it shows the path, I then copy+paste the command you mention into terminal and press enter.

    It gives me nothing, besides saying "Users/[Username]/Music is a directory"

    However, when I copy+paste the command after my home folder path, it gives me a full tree listing of my entire user folder/directory.

    I have no idea why it works for one but not the other.

    Any help is greatly appreciated. :):)

    Thanks.
     
  8. rhoydotp macrumors 6502

    rhoydotp

    Joined:
    Sep 28, 2006
    #8
    try something like this

    Code:
    find ~/Music/iTunes/iTunes\ Music -type d -depth 2
    if you want to get rid of the leading directory path

    Code:
    find ~/Music/iTunes/iTunes\ Music -type d -depth 2| sed 's/^.*iTunes Music\///'
    hope that helps.
     
  9. switon, Dec 19, 2012
    Last edited: Dec 19, 2012

    switon macrumors 6502a

    Joined:
    Sep 10, 2012
    #9
    RE: mdfind vs. find vs. ls ...

    Hi all,

    May I make one more suggestion?

    The "find" and "ls" terminal commands work well, but I'd like to suggest the possible use of the "mdfind" command too. There are a couple of reasons, mostly for speed. In my hands, I find the "mdfind" commands to be faster for network shared drives. The reason is because searching the Spotlight indexing just appears to be significantly faster when searching a network drive from another machine. (Of course, the network drive must have Spotlight indexing turned on and the indexing must have already been performed before you can use "mdfind".)

    For instance, when searching an iTunes Library with about 10000 songs on a network share (disk drive mounted on a Mac mini and shared via AFP) wirelessly from a rMBP, I found that the "find" command takes roughly 78 seconds while the "mdfind" command takes roughly 1 second.

    In particular, the following two commands first change the directory to the shared network disk directory for the iTunes Library and then performs the "find" command to find the "Phantom of the Opera" songs. Since the "find" is running from the rMBP over the wireless network, this command executed in roughly 78 seconds:

    Code:
    cd /Volumes/Music/iTunes-Classical-AAC
    find . -iname "*phantom*" -print
    
    On the other hand, the following two commands first change the directory to the shared network disk directory for the iTunes Library and then performs the "mdfind" command to find the "Phantom of the Opera" songs. This command executed in roughly 1 second (too short for me to effectively time with my watch).

    Code:
    cd /Volumes/Music/iTunes-Classical-AAC
    mdfind -onlyin . phantom
    
    Both commands, run with the appropriate "sed" post-massaging, gave:

    Code:
    Andrew Lloyd Webber/The Phantom Of The Opera [Disc 2]/2-07 Down Once More_Track Down This Murderer 1.m4a
    Andrew Lloyd Webber/The Phantom Of The Opera [Disc 2]/2-06 The Point of No Return 1.m4a
    Andrew Lloyd Webber/The Phantom Of The Opera [Disc 2]/2-05 Wandering Child_Bravo Monsieur 1.m4a
    Andrew Lloyd Webber/The Phantom Of The Opera [Disc 2]/2-04 Wishing You Were Somehow Here Again 1.m4a
    Andrew Lloyd Webber/The Phantom Of The Opera [Disc 2]/2-03 Notes_Twisted Every Way 1.m4a
    Andrew Lloyd Webber/The Phantom Of The Opera [Disc 2]/2-02 Masquerade_Why So Silent 1.m4a
    Andrew Lloyd Webber/The Phantom Of The Opera [Disc 2]/2-01 Entr'Acte 1.m4a
    Andrew Lloyd Webber/The Phantom Of The Opera [Disc 2]
    Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]/1-14 All I Ask Of You 1.m4a
    Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]/1-13 All I Ask Of You 1.m4a
    Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]/1-12 Why Have You Brought Me Here..._Raoul, I've Been There... 1.m4a
    Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]/1-11 Poor Fool, He Makes Me Laugh 1.m4a
    Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]/1-10 Notes..._Prima Donna 1.m4a
    Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]/1-09 Magical Lasso... 1.m4a
    Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]/1-08 I Remember..._Stranger Than You Dreamt It... 1.m4a
    Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]/1-07 Music Of The Night 1.m4a
    Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]/1-06 Phantom Of The Opera 1.m4a
    Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]/1-05 Little Lotte..._The Mirror... (Angel Of Music) 1.m4a
    Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]/1-04 Angel Of Music 1.m4a
    Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]/1-03 Think Of Me 1.m4a
    Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]/1-02 Overture 1.m4a
    Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]/1-01 Prologue 1.m4a
    Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]
    
    So, to summarize, in my hands wirelessly searching an iTunes Library with about 10000 songs on a network disk took roughly 1 second using "mdfind" and roughly 78 seconds using "find".

    ... This is just another suggestion for searching large networked directory trees. The same "mdfind" will not only search iTunes Libraries but also iPhoto Libraries as well as any other directory trees.

    Edit: And, of course, the "mdfind" command can search for other Spotlight indexing metadata also. See the "man mdfind" manpage for more information.

    Regards,
    Switon
     
  10. rhoydotp macrumors 6502

    rhoydotp

    Joined:
    Sep 28, 2006
    #10
    switon, you seem to be really good at OSX and that's great for this community ... and I'm serious :apple:

    the problem that I see with mdfind is that it might not be as robust as "find". for example, the OP is specifically looking for directory listing only. with find, I can do that with just the "type". is there a way to do that using "mdfind" easily?

    another thing is familarity with the "find" command which exists on most (of not all) unix variants.

    for sure, every second help especially if you use it inside the script.
     
  11. switon macrumors 6502a

    Joined:
    Sep 10, 2012
    #11
    RE: find...mdfind...

    Hi rhoydotp,

    Absolutely! I totally agree, and, in fact, I almost always write scripts with both "find" and "mdfind" commands in them. The reason being that (i) I came from the unix world and so "find" is a natural, and (ii) this way if Spotlight has not done its indexing on a particular volume then the unix "find" will work.

    The only reason I suggested "mdfind" is because I personally find (pun intended) that "find" over the network is slow while "mdfind" is fast, and I find (pun intended) this very useful. But all finds aside, I agree that "find" is much more general than "mdfind" and will work for cases where the volume has not undergone Spotlight indexing.

    And yes, if you search through the Spotlight metadata you can do similar searches for directories, etc. that you can do with "find"'s "-type d" option.

    Regards,
    Switon

    P.S. Thanks for the kind remarks ... I'm just trying my best to be helpful and I never wish to step on anyone's toes, so to speak.
     

Share This Page