$ dir
Magi The Labyrinth Of Magic Episode 1 English Dubbed.mp4
Magi The Labyrinth Of Magic Episode 2 English Dubbed.mp4
Magi The Labyrinth Of Magic Episode 3 English Dubbed.mp4
Magi The Labyrinth Of Magic Episode 4 English Dubbed.mp4
Magi The Labyrinth Of Magic Episode 5 English Dubbed.mp4
Magi The Labyrinth Of Magic Episode 6 English Dubbed.mp4
Magi The Labyrinth Of Magic Episode 6 English Dubbed.mp4-1.part
$ rename -n 's/Magi\ The\ Labyrinth\ Of\ Magic\ Episode\ {1..5}.+mp4/MTLOM\ \(DUB\)\ 0*{1..5}.mp4/g' *
Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/Magi\ The\ Labyrinth\ Of\ Magic\ Episode\ { <-- HERE 1..5}+mp4/ at (eval 1) line 1.
Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/Magi\ The\ Labyrinth\ Of\ Magic\ Episode\ { <-- HERE 1..5}+mp4/ at (eval 2) line 1.
Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/Magi\ The\ Labyrinth\ Of\ Magic\ Episode\ { <-- HERE 1..5}+mp4/ at (eval 3) line 1.
Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/Magi\ The\ Labyrinth\ Of\ Magic\ Episode\ { <-- HERE 1..5}+mp4/ at (eval 4) line 1.
Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/Magi\ The\ Labyrinth\ Of\ Magic\ Episode\ { <-- HERE 1..5}+mp4/ at (eval 5) line 1.
Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/Magi\ The\ Labyrinth\ Of\ Magic\ Episode\ { <-- HERE 1..5}+mp4/ at (eval 6) line 1.
我想重命名一些文件而不重命名其他文件;在 30 个文件中,要忽略的文件是第六个文件 6、16、8、28 和 19。
答案1
如果总共有 30 个文件,则重命名除文件 6、8、16、19 和 28 之外的所有文件:
$ rename -n 's/Magi The Labyrinth Of Magic Episode ([^68][^689]?|18|26|29) .+mp4/MTLOM (DUB) $1.mp4/g' *
rename(Magi The Labyrinth Of Magic Episode 10 English Dubbed.mp4, MTLOM (DUB) 10.mp4)
rename(Magi The Labyrinth Of Magic Episode 11 English Dubbed.mp4, MTLOM (DUB) 11.mp4)
rename(Magi The Labyrinth Of Magic Episode 12 English Dubbed.mp4, MTLOM (DUB) 12.mp4)
rename(Magi The Labyrinth Of Magic Episode 13 English Dubbed.mp4, MTLOM (DUB) 13.mp4)
rename(Magi The Labyrinth Of Magic Episode 14 English Dubbed.mp4, MTLOM (DUB) 14.mp4)
rename(Magi The Labyrinth Of Magic Episode 15 English Dubbed.mp4, MTLOM (DUB) 15.mp4)
rename(Magi The Labyrinth Of Magic Episode 17 English Dubbed.mp4, MTLOM (DUB) 17.mp4)
rename(Magi The Labyrinth Of Magic Episode 18 English Dubbed.mp4, MTLOM (DUB) 18.mp4)
rename(Magi The Labyrinth Of Magic Episode 1 English Dubbed.mp4, MTLOM (DUB) 1.mp4)
rename(Magi The Labyrinth Of Magic Episode 20 English Dubbed.mp4, MTLOM (DUB) 20.mp4)
rename(Magi The Labyrinth Of Magic Episode 21 English Dubbed.mp4, MTLOM (DUB) 21.mp4)
rename(Magi The Labyrinth Of Magic Episode 22 English Dubbed.mp4, MTLOM (DUB) 22.mp4)
rename(Magi The Labyrinth Of Magic Episode 23 English Dubbed.mp4, MTLOM (DUB) 23.mp4)
rename(Magi The Labyrinth Of Magic Episode 24 English Dubbed.mp4, MTLOM (DUB) 24.mp4)
rename(Magi The Labyrinth Of Magic Episode 25 English Dubbed.mp4, MTLOM (DUB) 25.mp4)
rename(Magi The Labyrinth Of Magic Episode 26 English Dubbed.mp4, MTLOM (DUB) 26.mp4)
rename(Magi The Labyrinth Of Magic Episode 27 English Dubbed.mp4, MTLOM (DUB) 27.mp4)
rename(Magi The Labyrinth Of Magic Episode 29 English Dubbed.mp4, MTLOM (DUB) 29.mp4)
rename(Magi The Labyrinth Of Magic Episode 2 English Dubbed.mp4, MTLOM (DUB) 2.mp4)
rename(Magi The Labyrinth Of Magic Episode 30 English Dubbed.mp4, MTLOM (DUB) 30.mp4)
rename(Magi The Labyrinth Of Magic Episode 3 English Dubbed.mp4, MTLOM (DUB) 3.mp4)
rename(Magi The Labyrinth Of Magic Episode 4 English Dubbed.mp4, MTLOM (DUB) 4.mp4)
rename(Magi The Labyrinth Of Magic Episode 5 English Dubbed.mp4, MTLOM (DUB) 5.mp4)
rename(Magi The Labyrinth Of Magic Episode 7 English Dubbed.mp4, MTLOM (DUB) 7.mp4)
rename(Magi The Labyrinth Of Magic Episode 9 English Dubbed.mp4, MTLOM (DUB) 9.mp4)
使用()
保存图案并$1
引用它。我不确定您希望在0*
替换中发生什么 - 我只是把它拿出来。根据需要进行调整。
我去掉了不必要的逃避
关于正则表达式的说明
-[^68][^689]?|18|26|29
匹配任意字符,但6
或8
后跟任意字符,但6
,,8
或9
,或,匹配18
,或,匹配26
,或,匹配29
。不太优雅...