Sunday, May 4, 2014

Copying multiple music files from multiple directories to a single destination

I came across another requirement of doing some task quickly by using the power of Linux shell commands. I had a directory called "Entertainment" which contained a huge collection of various kinds of files. One contained a collection of English songs while another contained Sinhala songs. Some other directories contained some miscellaneous things such as relaxing piano tunes, movies and stuff.

Suddenly, oneday I thought I should copy the mp3 music I have into my phone so that I can listen to them on the go. Filtering out the mp3 files from the complex directory hierarchy and copying them to a single destination directory seemed a hard work if I do it manually one by one. This is where the power of Linux shell comes into play a role. I had to search in the web to find the correct combination of commands to do the trick on the way I wanted it. Here is what finally I used to copy the mp3 files distributed over a hierarchy of directories inside the "Entertainment" directory into a single destination which is "~/Desktop/mp3music/".

find Entertainment/ -iname "*.mp3" -type f -exec cp {} ~/Desktop/mp3music/ \;


No comments:

Post a Comment