jesusjsc

Linux中rename命令
# Linux中rename命令 --- 需求:下列文件是由“title-id.mp4”组成的,需要将...
扫描右侧二维码阅读全文
05
2019/06

Linux中rename命令

Linux中rename命令


需求:下列文件是由“title-id.mp4”组成的,需要将如下文件批量修改成按照“id-title.mp4”组成的形式

[email protected]:~/test$ ll
total 0
drwxrwxrwx 0 jiangsichong jiangsichong 512 Apr  6 10:18 ./
drwxr-xr-x 0 jiangsichong jiangsichong 512 Apr  6 09:57 ../
-rw-rw-rw- 1 jiangsichong jiangsichong   0 Apr  6 10:18 Hook Lift Trailer-559477891078785.mp4
-rw-rw-rw- 1 jiangsichong jiangsichong   0 Apr  6 10:18 LifeVac Save A Life In A Choking Emergency-586767355016505.mp4
-rw-rw-rw- 1 jiangsichong jiangsichong   0 Apr  6 10:18 Wingjump Aeronautics That Improves Skiing Experience-564951587198082.mp4
-rw-rw-rw- 1 jiangsichong jiangsichong   0 Apr  6 10:18 zSpace Virtual Reality Learning Experience-574081559618418.mp4          

命令如下:

[email protected]:~/test$ rename 's/(.*)-(\d{15})\.mp4$/$2-$1\.mp4/' *.mp4
[email protected]:~/test$ ll
total 0
drwxrwxrwx 0 jiangsichong jiangsichong 512 Apr  6 10:23 ./
drwxr-xr-x 0 jiangsichong jiangsichong 512 Apr  6 09:57 ../
-rw-rw-rw- 1 jiangsichong jiangsichong   0 Apr  6 10:18 559477891078785-Hook Lift Trailer.mp4
-rw-rw-rw- 1 jiangsichong jiangsichong   0 Apr  6 10:18 564951587198082-Wingjump Aeronautics That Improves Skiing Experience.mp4
-rw-rw-rw- 1 jiangsichong jiangsichong   0 Apr  6 10:18 574081559618418-zSpace Virtual Reality Learning Experience.mp4
-rw-rw-rw- 1 jiangsichong jiangsichong   0 Apr  6 10:18 586767355016505-LifeVac Save A Life In A Choking Emergency.mp4

命令格式:

Usage: rename [-v] [-n] [-f] perlexpr [filenames]

参数说明:
v:显示文件重命名的细节
n:不执行重命名,但会模拟执行重命名。测试很有用
f:强制覆盖同名文件

例子:

rename 's/【.*-(\d*)】(.*)_(\d*)/$2_$1_$3/' *.jpg
Last modification:May 29th, 2019 at 11:06 am
If you think my article is useful to you, please feel free to appreciate

Leave a Comment