Renaming files with a lot of spaces

I just want to rename a bunch of files on a Linux-Streaming-Server.
So my first approache was to substitute foo with bar
 for file in *; do mv $file `echo $file | sed -r “s/foo/bar/”`; done
But since the bash separator is a space this will not work with files which contains spaces.
So I have to remove or substitute the spaces before. I used translate (tr) to change the spaces to underlines:
 for file in *; do mv “$file” `echo $file | tr ‘ ‘ ‘_’`; done
An other approache is to change the bash seperator.


  1. I have seen rename, but still have the problem with the spaces in file names.
    mmv looks interesting, but it does not look like it can handle spaces in file names.

  2. Also mmv can do this very easily.

  3. Most Linux distributions also come with the <a href="" rel="nofollow">rename(1)</a> command which helps you doing stuff like that.