help required with for loops

I have md5 files in a directory ./
I have the movie files in their own directories in ./ These use the same names as the md5 files (minus the appended “.md5”). You know how long movies names can be with all the and ] and ( and ) and underscores, spaces, and dots.

What I want to do, is make a ‘for loop’ that will take each md5, and mv them into their respective directories. How do I start to tackle this? If for loop is not the answer, please point me in the right way.


cd md5directory
for i in *.md5
  mv "$i" moviedirectory/"$base"

Forward-Slashiness does the trick eh? I will try it out tomorrow! Thanks.

If forward slash removes the trailing PATTERN ($i/.md5), what removes the prefixed pattern?

I have 50 files that begin with “0-” (zero dash) and I want to remove the “0-” from all of them.

Also, where can I read on that command i/.md5 ?

for i in *; do base=${i/0-0-/}; mv $i $base; done

This page was very helpful ->> Shell Geek: Rename Multiple Files At Once :: the How-To Geek

Have a look in man bash, near ${parameter/pattern/string}. The / is the general substitution case, while ${parameter#word} deletes word from the beginning and ${parameter%word} deletes word from the end.