我正在尝试批量重命名多个文件,到目前为止,我非常接近我想要实现的目标。我有一些名为" website.txt"," website1.txt"," website2.txt"," website3.txt"我试图只重命名与其关联的数字的文件(因此排除" website.txt")。我的第一次尝试如下(我使用-n进行测试):
rename -n 's/website/website_edit/' *txt
结果:
rename(website1.txt, website_edit1.txt)
rename(website2.txt, website_edit2.txt)
rename(website3.txt, website_edit3.txt)
rename(website.txt, website_edit.txt)
正如您所看到的,它几乎可以正常工作,但它正在重命名" website.txt"文件也是我不想要的。所以试着删除它我做了这个:
rename -n 's/website\w/website_edit/' *txt
结果:
rename(website1.txt, website_edit.txt)
rename(website2.txt, website_edit.txt)
rename(website3.txt, website_edit.txt)
这次它确实删除了#34; website.txt"从列表中,它也删除了新名称末尾的数字。我也尝试过使用一些正则表达式,但无济于事。
答案 0 :(得分:1)
试试这个:
rename -n 's/website(\d+)/website_edit$1/' *txt
____ __
^ ^
| |
capturing at least one digit captured group