Posted on by | Posted in Administrator Blog

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.


3 Responses to Renaming files with a lot of spaces

  1. joschi says:

    Most Linux distributions also come with the rename(1) command which helps you doing stuff like that.

  2. Michael says:

    Also mmv can do this very easily.

  3. 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.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.