Search code examples
regexcygwinrenamefile-rename

rename regex not working in cygwin


I am using cygwin under windows 7. In my directory there are files like

fort.100 fort.101 ... fort.1xx

I want to give them all an extension _v1. When I try to achieve it using rename by

rename 's/$/_v1/' fort.*

the prompt exit with no errors and nothing happens. I then tried

rename -e 's/$/_v1/' fort.*, an error pops up,
rename: unknown option -- e

I also tried with a different delimiter @ instead of / with no luck.

Now, I thought it was due to the character _ in the expression (I am a newbie to regex), I tried escaping it by \_ with no luck either. Again a try without _, for example,

rename 's/$/v11/' fort.* - nothing happens again.

Although I achieved my goal by

for file in fort.*; do mv $file $file\_v1; done, I wonder why rename doesn't work.

What am I doing wrong here? Is it because I am on cygwin?


Solution

  • I have found a workaround. I replaced the util-linux rename to perl rename a separate package. This was provided from @subogero from GitHub.
    All the usual rename expressions is working.