重命名正则表达式在 cygwin 中不起作用

rename regex not working in cygwin

我在 windows 7 下使用 cygwin。 在我的目录中有像

这样的文件

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

我想给他们都延期_v1。 当我尝试使用 rename by

实现它时

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

提示没有错误退出并且没有任何反应。 然后我尝试了

rename -e 's/$/_v1/' fort.*,弹出错误,
rename: unknown option -- e

我也尝试过使用不同的分隔符 @ 而不是 / 但没有成功。

现在,我认为这是由于表达式中的字符 _ 造成的(我是 regex 的新手),我尝试通过 \_ 转义它,但也没有成功.再试一次没有 _,例如

rename 's/$/v11/' fort.* - 什么也没有发生。

虽然我通过

实现了我的目标

for file in fort.*; do mv $file $file\_v1; done,我想知道为什么rename不起作用。

我在这里做错了什么?是因为我用的是cygwin吗?

rename的说明书与您的期望不符。 我看不到正则表达式功能。

SYNOPSIS
       rename [options] expression replacement file...

DESCRIPTION
       rename  will  rename  the specified files by replacing the first occur‐
       rence of expression in their name by replacement.

OPTIONS
       -v, --verbose
              Give visual feedback which files where renamed, if any.

       -V, --version
              Display version information and exit.

       -s, --symlink
              Peform rename on symlink target

       -h, --help
              Display help text and exit.

EXAMPLES
       Given the files foo1, ..., foo9, foo10, ..., foo278, the commands

              rename foo foo0 foo?
              rename foo foo0 foo??

       will turn them into foo001, ..., foo009, foo010, ..., foo278.  And

              rename .htm .html *.htm

       will fix the extension of your html files.

对于您想达到的简单方法是:

for i in fort*; do mv ${i} ${i}_v1 ; done

我找到了解决方法。 我将 util-linux rename 替换为 perl rename 一个单独的包。 这是从 GitHub.
@subogero 提供的 所有常用的 rename 表达式都有效。