从文件名中删除日期,但保留文件扩展名 [英] remove date from filename but keep the file extension
本文介绍了从文件名中删除日期,但保留文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在名为current_dir的目录中有这样的文件:
I have files like these in a directory called current_dir:
my data-file 2014-10.txt
data file201409.txt
我想要
my data-file.txt
data file.txt
这是我尝试过的
rename 's/ *[0-9]{4}-?[0-9]{2}.*$//' current_dir/*.txt
但它也删除了.txt扩展名.
but it removed the .txt extension as well.
我对linux还是很陌生,有人可以帮助我吗?
I'm quite new to linux, could anyone help me?
推荐答案
重命名仅替换匹配的部分,因此从正则表达式中删除.* $
会保留 .txt
rename only replaces the matched part so removing .*$
from the regular expression keeps the .txt
rename 's/ *[0-9]{4}-?[0-9]{2}//' current_dir/*.txt
示例
$ rename -n 's/ *[0-9]{4}-?[0-9]{2}//' *.txt
rename(data file201409.txt, data file.txt)
rename(my data-file 2014-10.txt, my data-file.txt)
这篇关于从文件名中删除日期,但保留文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文