You are not logged in.

#1 2008-02-02 21:08:12

fwojciec
Member
Registered: 2007-05-20
Posts: 1,411

[solved] bash / rename problem

I'm trying to rename some mp3 files but I've run into a problem.  The filenames begin with a hyphen (something like this, for example: "- 1. song name.mp3") which seems to affect how the mv command behaves...  Anyways, here is the command I used:

for i in *.mp3; do j=`echo $i | sed 's/-\ /0/g'`; mv "$i" "$j"; done

and here is the output I get:

mv: invalid option --  
Try `mv --help' for more information.
mv: invalid option --  
Try `mv --help' for more information.
(...)

I guess the hyphen from the filename gets interpreted by the mv command as an unrecognized option.  Is there any way to escape this hyphen somehow?  I can rename these files using thunar batch rename without problems but I'd love to learn how to deal with cases like this in the future.  Thanks for any help with this.

Last edited by fwojciec (2008-02-02 21:45:47)

Offline

#2 2008-02-02 21:22:21

Gilneas
Member
From: Netherlands
Registered: 2006-10-22
Posts: 320

Re: [solved] bash / rename problem

Use "mv --"
You may also like mmv in AUR.

Offline

#3 2008-02-02 21:25:45

fwojciec
Member
Registered: 2007-05-20
Posts: 1,411

Re: [solved] bash / rename problem

Thanks, "mv --" works great.  I'll have a look at mmv as well.

Offline

Board footer

Powered by FluxBB