在Unix中根据模式重命名多个文件 [英] Rename multiple files based on pattern in Unix

查看:27
本文介绍了在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(与<相同a href="https://stackoverflow.com/questions/1086502/rename-multiple-files-at-once-in-unix/1086519#1086519">Judy2K 的回答):

rename fgh jkl fgh*

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

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

这篇关于在Unix中根据模式重命名多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆