-2

Someone said to me use the find command but I'm not exactly sure how to do it.

Basically I need this:

suppose I have a folder called dir1 and it contains three sub-directories (dir2, dir3 and dir4 respectively) and suppose there might be mp3 files in all of the aforementioned directories. I would like to run a terminal command on dir1 that would search recursively through all the folders and list full paths of where it finds mp3 files. I need the full paths so that I know exactly where they were found.

Output should look something like this:

/Users/joeschomoe/dir1/Daft Punk - Around The World.mp3
/Users/joeschomoe/dir1/dir2/Jimi Hendrix - All Along The Watchtower.mp3
/Users/joeschomoe/dir1/dir2/Jimi Hendrix - Purple Haze.mp3
/Users/joeschomoe/dir1/dir3/Rolling Stones - Gimme Shelter.mp3
/Users/joeschomoe/dir1/dir4/Simon and Garfunkel - The Boxer.mp3

Would anyone know how to do this with find or some other Unix command I'm not aware of?

Any help would be gladly appreciated in advance. Thanks.

user41157
  • 189
  • 2
  • 9

1 Answers1

4

find dir1 -name '*.mp3' -print will do it. -name and -iname are case-sensitive and case-insensitive matches for find.

Daniel Pittman
  • 5,692
  • 1
  • 22
  • 20
  • Beautiful! Thank you so much. This will help. Now I have one more thing to ask even though you've already been so helpful. How would I adjust the regular expression so that I can find more than one type of music file. Say, m4a files for example. I tried '*.mp3|*.m4a' but it didn't work. – user41157 Mar 16 '12 at 05:47
  • 1
    Reading the manual page should help, but `-name '*.mp3' -o -name '*.m4a'` will do what you want. – Daniel Pittman Mar 16 '12 at 05:48