Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted

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

share|improve this answer
    
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 5: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 5:48
add comment

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.