-   Linux - Newbie (
-   -   Cannot replace spaces w/ underscores (

clem_c_rock 09-27-2007 12:12 PM

Cannot replace spaces w/ underscores
I'm desperately trying to replace some files w/ spaces in the names w/ underscores.

I ran this command in a directory: rename " " _ *\ * and it worked like a charm on every file except this one:

MissMarieBand_Oh_No!_Not Again.wmv

I then tried to take to remove the spaces w/ this: rename "s/ *//g" *.mov

and it still ignores this file.

Is there any way I can get around this?


matthewg42 09-27-2007 12:30 PM

The *.mov in the command you specified:

rename "s/ *//g" *.mov
Means the command will only apply to files which end in ".mov", so it should not work on one ending in ".wmv", like the one you named.

tredegar 09-27-2007 12:32 PM

I think the problem is the "!" in the filename - it shouldn't be there.

pixellany 09-27-2007 12:33 PM


rename " " _ *\ *
I don't see what the syntax of this is.


rename "s/ *//g" *.mov
operates on all files ending in ".mov", but yours ends in ".wmv" Also, it only replaces 2 or more occurences of " ". Try 's/ //g'

tredegar 09-27-2007 12:41 PM

For example:

tg@vaio:~$ touch "MissMarieBand_Oh_No!_Not Again.wmv"
bash: !_Not: event not found
tg@vaio:~$ touch "MissMarieBand_Oh_No\!_Not Again.wmv"
tg@vaio:~$ ls Miss*
MissMarieBand_Oh_No\!_Not Again.wmv

So get rid of the "!"
Edit: Like this:

tg@vaio:~$ mv MissMarieBand_Oh_No\!_Not\ Again.wmv  MissMarieBand_Oh_No_Not_Again.wmv

rsashok 09-27-2007 12:54 PM

Try this, it worked on my pc:
mv MissMarieBand_Oh_No\!\ Again.wmv MissMarieBand_Oh_No\!_Again.wmw

I hope it is a good song.

pixellany 09-27-2007 12:56 PM

I oopsed---"*" means ZERO or more instances of the previous expression. Here is the para from "man regex"

A piece is an atom possibly followed by a single(!) `*', `+', `?', or
bound. An atom followed by `*' matches a sequence of 0 or more matches
of the atom. An atom followed by `+' matches a sequence of 1 or more
matches of the atom. An atom followed by `?' matches a sequence of 0
or 1 matches of the atom.

And, yes, ANY special character in a filename is bad news....

clem_c_rock 09-27-2007 02:17 PM

Great - thanks for all the feedback. I am a command line tard for sure.

This did the trick for me:

mv MissMarieBand_Oh_No\!_Not\ Again.wmv MissMarieBand_Oh_No_Not_Again.wmv

All times are GMT -5. The time now is 04:40 AM.