#!/bin/bash # # renaming *.mp3 in the current directory # according to the following rules: # # # uppercase -> lowercase ('Artist - Title.mp3' -> 'artist - title.mp3') # # 'ä', 'ö', 'ü' -> 'ae', 'oe', 'ue' ('artist - title-ä.mp3' -> artist - title-ae.mp3') # # ' ' -> '_' ('artist - title.mp3' -> 'artist_-_title.mp3') # # '&', '+' -> 'and' ('artist1_&_artist2___title(2005).mp3' -> ''artist1_and_artist2___title(2005).mp3') # # '(' -> '__' and ')' -> '' ('artist___title(2005).mp3' -> 'artist___title__2005.mp3') # # '_-_' -> '___' ('artist_-_title.mp3' -> 'artist___title.mp3') # # # to replace more characters just add a '| sed "s/$what_to_rename/$newchar/g"' in front of the ')' for file in *.mp3; do { newfile=$(echo "$file" | tr [:upper:] [:lower:] | sed "s/[ö|Ö]/oe/g" | sed "s/[ä|Ä]/ae/g" | sed "s/[Ü|ü]/ue/g" | sed "s/ /_/g" | sed "s/[&|+]/and/g" | sed "s/(/__/g" | sed "s/)//g" | sed "s/_-_/___/g") if [ "$file" == "$newfile" ]; then sleep 0; else mv -v "$file" "$newfile"; fi } done