在Unix中根据模式重命名多个文件

在Unix中根据模式重命名多个文件

问题描述:

一个目录中有多个文件以前缀fgh开头,例如:

There are multiple files in a directory that begin with prefix fgh, for example:

fghfilea
fghfileb
fghfilec

我想将它们全部重命名为以前缀 jkl 开头.是否有一个命令可以做到这一点,而不是单独重命名每个文件?

I want to rename all of them to begin with prefix jkl. Is there a single command to do that instead of renaming each file individually?

有几种方法,但使用 rename 可能是最简单的.

There are several ways, but using rename will probably be the easiest.

使用一个版本的rename:

Using one version of rename:

rename 's/^fgh/jkl/' fgh*

使用另一个版本的rename(与Judy2K 的回答):

rename fgh jkl fgh*

您应该查看您平台的手册页以了解以上哪一项适用.

You should check your platform's man page to see which of the above applies.