Batch Process in Bash

I make this entry (at 0230) because Joe just asked me how to do it, hence someone else in the world might also want to do it. The quest is, to do something to a large group of files in linux. For example convert a folder of wma files to mp3’s (for this example you will need to have ffmpeg installed). We add the condition that we want to keep the file names as they are, and just convert them.

Simple! We will write a little script to this for us (although you could do it straight from the terminal), for this example we write a script called wma2mp3 (obviously change gedit for your favourite editor):

gedit wma2mp3

Now add to that,

for i in *.wma; do
ffmpeg -i “$filename.wma” “$filename.mp3”

Then all you need to do is place that in the folder you want to run it, run it, and then bang you’re done! Again this is just an example, if you actually want to change wma’s to mp3’s there are a few more options you may want to use, but I thought this would be a better ‘template’. So for one for more example, say you want to convert all your ps files in a folder to pdf’s (here you will need to have ps2pdf installed) we would use:

for i in *.ps; do
ps2pdf “$” “$filename.pdf”

Hope that helps!

One thought on “Batch Process in Bash

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.