execute a command in all subdirectories bash

Posted by Luigi R. Viggiano on Super User See other posts from Super User or by Luigi R. Viggiano
Published on 2013-06-16T13:58:20Z Indexed on 2013/07/02 23:09 UTC
Read the original article Hit count: 392

Filed under:
|
|
|

I have a directory structure composed by:

iTunes/Music/${author}/${album}/${song.mp3}

I implemented a script to strip my mp3 bitrate to 128 kbps using lame (which works on a single file at time). My script looks like this 'normalize_mp3.sh':

#!/bin/bash
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for f in *.mp3
do
  lame --cbr $f __out.mp3
  mv __out.mp3 $f
done
IFS=$SAVEIFS

This works fine, if I go folder by folder and execute this command.

But I'd like to have a "global" command, like in 4DOS so I can run:

$ cd iTunes/Music
$ global normalize_mp3.sh

and the global command would traverse all subdirs and execute the normalize_mp3.sh to strip all my mp3 in all subfolders.

Anyone knows if there is a unix equivalent to the 4dos global command? I tried to play with find -exec but I just managed to get an headache.

© Super User or respective owner

Related posts about osx

Related posts about command-line