All you're doing is trying to exectute the new names. Try something like this: for file in *.mp3;do newname=`sed s/CCC-\([0-9]+\)-\([0-9]+\)-\([0-9]+\).mp3/\3\1\2\.mp3/` mv $file $newname done