如何删除文件名中的数字?
在下面的示例中,如您所见,我想删除零
$ rename -n 's/Season\ (\d{2})\ Episode\ (\d{2}).+(\D{2})/Season\ $1\ Episode\ $2.mp4/' *
Season 01 Episode 01.mp4 renamed as Season 01 Episode 01.mp44
Season 01 Episode 02.mp4 renamed as Season 01 Episode 02.mp44
Season 01 Episode 03.mp4 renamed as Season 01 Episode 03.mp44
Season 01 Episode 04.mp4 renamed as Season 01 Episode 04.mp44
Season 01 Episode 05.mp4 renamed as Season 01 Episode 05.mp44
Season 01 Episode 06.mp4 renamed as Season 01 Episode 06.mp44
Season 01 Episode 07.mp4 renamed as Season 01 Episode 07.mp44
Season 01 Episode 08.mp4 renamed as Season 01 Episode 08.mp44
Season 01 Episode 09.mp4 renamed as Season 01 Episode 09.mp44
Season 01 Episode 10.mp4 renamed as Season 01 Episode 10.mp44
Season 01 Episode 11.mp4 renamed as Season 01 Episode 11.mp44
Season 01 Episode 12.mp4 renamed as Season 01 Episode 12.mp44
Season 01 Episode 13.mp4 renamed as Season 01 Episode 13.mp44
Season 01 Episode 14.mp4 renamed as Season 01 Episode 14.mp44
Season 01 Episode 15.mp4 renamed as Season 01 Episode 15.mp44
Season 01 Episode 16.mp4 renamed as Season 01 Episode 16.mp44
Season 01 Episode 17.mp4 renamed as Season 01 Episode 17.mp44
Season 01 Episode 18.mp4 renamed as Season 01 Episode 18.mp44
Season 01 Episode 19.mp4 renamed as Season 01 Episode 19.mp44
Season 01 Episode 20.mp4 renamed as Season 01 Episode 20.mp44
Season 01 Episode 21.mp4 renamed as Season 01 Episode 21.mp44
Season 01 Episode 22.mp4 renamed as Season 01 Episode 22.mp44
Season 01 Episode 23.mp4 renamed as Season 01 Episode 23.mp44
Season 01 Episode 25.mp4 renamed as Season 01 Episode 25.mp44
Season 01 Episode 26.mp4 renamed as Season 01 Episode 26.mp44
Season 02 Episode 00.mp4 renamed as Season 02 Episode 00.mp44
Season 02 Episode (this zero needs to be removed)***0***15.mp4 renamed as Season 02 Episode 01.mp44
Season 02 Episode ***0***16.mp4 renamed as Season 02 Episode 01.mp44
Season 02 Episode ***0***17.mp4 renamed as Season 02 Episode 01.mp44
Season 02 Episode ***0***18.mp4 renamed as Season 02 Episode 01.mp44
Season 02 Episode ***0***19.mp4 renamed as Season 02 Episode 01.mp44
Season 02 Episode 01.mp4 renamed as Season 02 Episode 01.mp44
Season 02 Episode ***0***20.mp4 renamed as Season 02 Episode 02.mp44
Season 02 Episode ***0***21.mp4 renamed as Season 02 Episode 02.mp44
Season 02 Episode 02.mp4 renamed as Season 02 Episode 02.mp44
Season 02 Episode 03.mp4 renamed as Season 02 Episode 03.mp44
Season 02 Episode 04.mp4 renamed as Season 02 Episode 04.mp44
Season 02 Episode 05.mp4 renamed as Season 02 Episode 05.mp44
Season 02 Episode 06.mp4 renamed as Season 02 Episode 06.mp44
Season 02 Episode 07.mp4 renamed as Season 02 Episode 07.mp44
Season 02 Episode 08.mp4 renamed as Season 02 Episode 08.mp44
Season 02 Episode 09.mp4 renamed as Season 02 Episode 09.mp44
Season 02 Episode 10.mp4 renamed as Season 02 Episode 10.mp44
Season 02 Episode 11.mp4 renamed as Season 02 Episode 11.mp44
Season 02 Episode 12.mp4 renamed as Season 02 Episode 12.mp44
Season 02 Episode 13.mp4 renamed as Season 02 Episode 13.mp44
Season 02 Episode 14.mp4 renamed as Season 02 Episode 14.mp44
并且如您所见,使用重命名命令也无法正确重命名扩展。我也知道重命名命令是错误的,所以请提供正确的命令。
答案1
以下更简单的表达可能就足够了:
rename -n 's/Season (\d{2}) Episode 0*(\d{2}).+mp4/Season $1 Episode $2.mp4/'
- 使用第二组开头
0*
的 0 来捕获两位数剧集编号前的多余的 0。 - 最后一组是不需要的。
- 您不需要逃避空格。