[英]Rename Multiple Files in a Directory in Linux
I have a requirement to rename all files (not single file) in a directory with the current time stamp in LINUX. 我需要使用LINUX中的当前时间戳重命名目录中的所有文件(而不是单个文件)。
For example: 例如:
abcd_001_@timestamp@_12345.txt, abcd_002_@timestamp@_56789.txt
to 至
abcd_001_20141205063435_12345.txt, abcd_002_20141205063435_56789.txt
I have used rename
command but unable to change the names. 我使用过rename
命令,但是无法更改名称。 Could someone help me here. 有人可以在这里帮助我。 A quick reply will be appreciated. 快速答复将不胜感激。
rename @timestamp@ $(date +%Y%m%d%H%M%S) *@timestamp@*
有关详细信息和更多示例,另请参见man rename
。
Do you just want to rename them manually, then you could use something like this: 您是否只想手动重命名它们,然后可以使用以下方法:
rename 's/@timestamp@/20141205063435/' *.txt
If you want to do it automatically you could use the date
command to give you the current date. 如果要自动执行此操作,可以使用date
命令为您提供当前日期。
rename "s/$(date)/$(date +%Y%m...)/" *.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.