2017-05-31 27 views
0

不工作我使用Windows 7 在我的目錄下的cygwin有像重命名正則表達式中的cygwin

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

文件,我想給他們所有的擴展_v1。 當我嘗試使用rename通過

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嗎?

+0

嘗試'重命名-E's/$/_ v1 /'堡壘。*' –

+0

@WiktorStribiżew不起作用,退出時出現錯誤'rename:unknown option -E'。 –

+0

如果你做一個'man rename',它是一個busybox light版本的二進制文件還是原始的binay? – Esteban

回答

0

我已經找到了解決辦法。 我將util-linux rename更換爲perl rename單獨的包裝。 這是@subogeroGitHub提供的。
所有常用的rename表達式都在起作用。

0

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 
+0

你所描述的全部都是我提出的問題。我想知道爲什麼以及如何使它工作。而且,我在問題中提供了您提到的同一個腳本。 –

+0

「爲什麼」是重命名手冊所說的。該功能在cygwin中提供的版本中不存在。 – matzeri