Bash:根据文件名重命名

时间:2018-12-20 23:50:16

标签: bash

(此处是bash newb;我很抱歉。)

我的文件夹中有数百个文件,例如

"Cool Stuff - Some Movie Series #14.mp4"
"Other Stuff - Some Movie Series #49.mp4"
"Further Stuff - Some Movie Series #48.mp4"

以此类推。

我想分别将它们重命名为

"14 Cool Stuff - Some Movie Series.mp4"
"49 Other Stuff - Some Movie Series.mp4"
"48 Further Stuff - Some Movie Series.mp4"

以此类推。

有直接的方法吗?

(一个可能会或可能不会有希望的解决方案是使用rename。例如,rename 's/Movie/Mxvxx/g' *将用x s替换元音。但是我无法做使用该策略时,会将#.mp4之间的数字分配给一个变量,然后将该变量放在文件名之前。因此,我担心rename是一种误导的策略。)< / p>

1 个答案:

答案 0 :(得分:1)

我认为引号不是文件名的一部分。

prename -n 's/(.*) #(.*)\.mp4/$2 $1.mp4/' *.mp4

输出:

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

如果输出正常,请删除-n