1

I tried to rename all file with extension "XLS;1" to "XLS" but it just didn't work.

I tried the following in cygwin in windows xp and they don't work:

mv *.XLS;1 *.XLS

mv *.XLS\;1 *.XLS

mv "*.XLS;1" *.XLS
  • I figured it out, but in the future you should include the exact error message you get, it helps a great deal in fixing things, especially like this where the actual problem isn't what you think it is. – Kevin Mar 02 '12 at 04:38
  • Oh...I thought the wildcard expansion will do the trick. Now the error message make sense, which I thought was just non-sense error message. – lamwaiman1988 Mar 02 '12 at 06:50
  • @lamwaiman1988 (and/or @Kevin), would you please update this with "the error message(s)"? For posterity. :) – pythonlarry Feb 07 '14 at 14:40
  • @PythonLarry I don't have cygwin to get the exact messages, but they should be something along the lines of "mv: foo.XLS: not a directory" and "bash: 1: command not found" – Kevin Feb 07 '14 at 14:49

3 Answers3

5

The problem isn't the semicolon, your second example would take care of that. The problem is that Linux/Unix utilities (and, by extension, Cygwin) don't take that instruction to mean "move all files ending in .XLS;1 to .XLS," as I understand Windows does. You need to move each file individually:

for file in *.XLS\;1; do 
    mv "$file" "${file%;1}"
done

An explanation:

This takes all files ending in .XLS;1 and stores them one at a time into a variable named $file. For each file, we tell it to move that $file to a new name we create by chopping ;1 off the back of $file.

N.b. For those using zsh, there is a nice utility called zmv:

zmv '(*).XLS;1" "$1.XLS"

Depending on your setup you may need to run autoload zmv first (put it in your .zshrc too).

Kevin
  • 40,767
1

You can move by inode.

To find the inode

ls -i 

using the inode you just found

find . -inum <you just found> -exec mv {} <new name> \;

That should work on a unix system. No idea about cygwin.

Greg Cain
  • 1,163
1

Cygwin has util-linux package which contains rename:

rename ".XLS;1" ".XLS" *.XLS\;1

Or if there are no other semicolons in the file names, this is enough:

rename ";1" "" *.XLS\;1
manatwork
  • 31,277