以数字为前缀按顺序对一堆文件进行编号

以数字为前缀按顺序对一堆文件进行编号

因此,我在 Linux 机器上有 58 个文件,文件名如下:

Theory of Computation (TOC) | Basics of TOC | Lec 1 | GATE Computer Science⧸IT Engineering Exam [7DOPjYGtnTQ].mp4
Theory of Computation (TOC) | Operations | Lec 2 | GATE Computer Science⧸IT Engineering Exam [XCm43gyfl4M].mp4
Theory of Computation (TOC) | Chomsky Hierarchy | Lec 3 | GATE Computer Science⧸IT Engineering Exam [_YvKlbKmbNg].mp4

每个文件名的讲座编号后面都有“Lec”。我想按以下方式在每个文件上连续添加数字:

1 - Theory of Computation (TOC) | Basics of TOC | Lec 1 | GATE Computer Science⧸IT Engineering Exam [7DOPjYGtnTQ].mp4
2 - Theory of Computation (TOC) | Operations | Lec 2 | GATE Computer Science⧸IT Engineering Exam [XCm43gyfl4M].mp4
3 - Theory of Computation (TOC) | Chomsky Hierarchy | Lec 3 | GATE Computer Science⧸IT Engineering Exam [_YvKlbKmbNg].mp4

我怎样才能做到这一点?

答案1

zsh

autoload -Uz zmv
zmv -n '*| Lec (<->) |*' '$1 - $f'

-n如果对结果满意,请删除(试运行)。

答案2

rename -n 's/\bLec\s+(\d+)/$1 - $_/' Theory*

dry-run如果输出看起来不错,请删除 -n ( )。

您需要的版本rename

$ rename 2>&1 | grep perl
[ -e|-E perlexpr]*|perlexpr [ files ]

相关内容