Linux Rename file with only time/date stamp

落爺英雄遲暮 提交于 2019-12-23 13:38:07

问题


I have a single file which I want to rename mv to year_month_day_h:m:s - whats the best way to do that?

I've tried the following but it doesn't dynamically add the correct stamp (original file actually has a backslash in the name):

mv getnw/myfilename.txt "%Y%m%d%H%M%S".txt mv getnw/myfilename.txt "%Y-%m%d%H%M%S".txt mv getnw/myfilename.txt %Y-%m%d%H%M%S.txt mv getnw/myfilename.txt "'date +%Y%m%d%H%M%S'.txt"


回答1:


mv myfile.txt `date +%Y_%m_%d_%H:%M:%S`.txt



回答2:


mv myfile.txt myfile`date -Is`.txt

is a shorter version

but : won't work with some of the unix commands like rsync or scp because it parses part of the name as a host address. use tr to change :

mv myfile.txt myfile`date -Is|tr : -`.txt

or

mv myfile.txt myfile$(date -Is|tr : -).txt


来源:https://stackoverflow.com/questions/10639088/linux-rename-file-with-only-time-date-stamp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!