[英]Bash: renaming files based on their names
(Bash newb here; my apologies.) (在这里抨击newb;我很抱歉。)
I have a folder of a couple hundred files like 我有一个包含数百个文件的文件夹
"Cool Stuff - Some Movie Series #14.mp4"
"Other Stuff - Some Movie Series #49.mp4"
"Further Stuff - Some Movie Series #48.mp4"
and so on. 等等。
I'd like to mass rename them to be, respectively 我想分别将它们重命名为
"14 Cool Stuff - Some Movie Series.mp4"
"49 Other Stuff - Some Movie Series.mp4"
"48 Further Stuff - Some Movie Series.mp4"
and so on. 等等。
Is there a straightforward way to do this? 有没有简单的方法可以做到这一点?
(One solution that may or may not be promising is to use rename
. For example, rename 's/Movie/Mxvxx/g' *
would replace the vowels with x
s. But what I'm unable to do with that strategy is assign the numbers that come between the #
and the .mp4
to a variable that I then prepend to the filename. So I fear that rename
is a misguided strategy.) (一个可能会或可能不会有希望的解决方案是使用rename
。例如, rename 's/Movie/Mxvxx/g' *
将用x
s替换元音。但是我无法使用该策略进行分配#
和.mp4
之间的数字到一个变量,然后我将该变量放在文件名之前。因此,我担心rename
是一种误导的策略。)
I assume the quotation marks are not part of the filename. 我认为引号不是文件名的一部分。
prename -n 's/(.*) #(.*)\.mp4/$2 $1.mp4/' *.mp4
Output: 输出:
Cool Stuff - Some Movie Series #14.mp4 renamed as 14 Cool Stuff - Some Movie Series.mp4 Further Stuff - Some Movie Series #48.mp4 renamed as 48 Further Stuff - Some Movie Series.mp4 Other Stuff - Some Movie Series #49.mp4 renamed as 49 Other Stuff - Some Movie Series.mp4
If output looks okay, remove -n
. 如果输出看起来可以,请删除-n
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.