Possible Duplicate:How to clean up file extensions? I'd like to rename files with extension .flac.mp3 to extension .mp3.I used the following command$ for i in *; do mv $i `echo $i | sed 's/.flac//g'`; doneThis writes for every file the following error message.mv: target `file.mp3' is not a directoryWhere am I doing mistake?thank you
Multiple renaming files
shell;command line;shell script;rename
Maybe these files have names containing whitespace.Simple rule of shell programming: Always use double quotes around variable and command substitutions (unless you know why you need to leave them out). So:for i in *; do mv $i $(echo $i | sed 's/.flac//g'); doneWhile you're at it, there are a few things you could do better in that command, even if they aren't the source of your problem. You should run your command only on the files it's supposed to affect, not every file in the current directory. The sed regexp .flac could match something other than the extension. The command may also fail if you have a file name that begins with a - or that contains a backslash (with some versions of echo).for i in *.flac.mp3; do mv -- $i $(echo $i | sed 's/\.flac\.mp3$/\.mp3/'); doneBut in fact you needn't bother with sed here, there's a shell construct to remove a suffix from a string.for i in *.flac.mp3; do mv -- $i ${i%.flac.mp3}.mp3; done-- ensures that even if $i begins with a -, it won't be interpreted as an option. An alternative method is to ensure that $i never begins with -, for example by ensuring that all relative file names are prefixed with ./ (which has no effect on what file is designated since . is the current directory).  for i in ./*.flac.mp3; do mv $i ${i%.flac.mp3}.mp3; doneThere are plenty of tools to automate file renamings; browse rename here for a few ideas. For example, if your shell is zsh:autoload zmv    # goes into your .zshrczmv '(*).flac.mp3' '$1.mp3'