在linux中使用正则表达式重命名文件 [英] Rename files using regular expression in linux
本文介绍了在linux中使用正则表达式重命名文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一组名为如下的文件:
I have a set of files named like:
Friends - 6x03 - Tow Ross' Denial.srt
Friends - 6x20 - Tow Mac and C.H.E.E.S.E..srt
Friends - 6x05 - Tow Joey's Porshe.srt
我想像下面这样重命名它们
and I want to rename them like the following
S06E03.srt
S06E20.srt
S06E05.srt
我应该怎么做才能在 linux 终端中完成工作?我已经安装了重命名,但使用以下方法出现错误:
what should I do to make the job done in linux terminal? I have installed rename but U get errors using the following:
rename -n 's/(\w+) - (\d{1})x(\d{2})*$/S0$2E$3\.srt/' *.srt
推荐答案
你忘记了星号前面的一个点:
You forgot a dot in front of the asterisk:
rename -n 's/(\w+) - (\d{1})x(\d{2}).*$/S0$2E$3\.srt/' *.srt
在 OpenSUSE、RedHat、Gentoo 上,您必须使用 Perl 版本的 rename
.这个答案展示了如何获得它.在 Arch 上,这个包被称为 perl-rename
.
On OpenSUSE, RedHat, Gentoo you have to use Perl version of rename
. This answer shows how to obtain it. On Arch, the package is called perl-rename
.
这篇关于在linux中使用正则表达式重命名文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文