如果您使用的是基于 debian 的 linux 系统,那么您可以使用接受 regular expressions 的重命名脚本来重命名文件。更多 info 因为我很难找到手册页。
例如
harald@Midians_Gate:~$ ls p*.php
parse.php pd.php pgrep.php preg_based.php proc.php
假设我想将扩展名更改为 .perl 并在名称前加上 file_
然后我使用命令:
rename -n 's/([a-z]*)\.php/file_$1.perl/' p*.php
会给
parse.php renamed as file_parse.perl
pd.php renamed as file_pd.perl
pgrep.php renamed as file_pgrep.perl
preg_based.php renamed as preg_file_based.perl
proc.php renamed as file_proc.perl
我选择并捕获基本文件名([a-z]*),然后在替换$1 中使用它并附加.perl 并在$1 前面加上常规字符串file_
-n 选项使其在不更改任何内容的情况下测试运行
从这个例子中你可以看到,你选择的正则表达式需要被正确考虑,否则你会得到像上面 preg_based.php 这样你想要 file_preg_based.perl 的情况:)
为了弥补我需要在这里使用([a-z_]*)
这是我一直坚持使用 debian 的众多原因之一,不过我很想找到其他非 debian 系统的等价物:-/