![以数字为前缀按顺序对一堆文件进行编号](https://linux22.com/image/213639/%E4%BB%A5%E6%95%B0%E5%AD%97%E4%B8%BA%E5%89%8D%E7%BC%80%E6%8C%89%E9%A1%BA%E5%BA%8F%E5%AF%B9%E4%B8%80%E5%A0%86%E6%96%87%E4%BB%B6%E8%BF%9B%E8%A1%8C%E7%BC%96%E5%8F%B7.png)
因此,我在 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
如果对结果满意,请删除(试运行)。