Linux Rename file only with time and date stamp

I have one file that I want to rename mv to year_month_day_h: m: s - what is the best way to do this?

I tried the following, but did not dynamically add the correct label (the source 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"

+4
source share
2 answers
 mv myfile.txt `date +%Y_%m_%d_%H:%M:%S`.txt 
+9
source
 mv myfile.txt myfile`date -Is`.txt 

- shorter version

but : will not work with some unix commands, such as rsync or scp, because it parses part of the name as the host address. use tr to change :

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

or

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

Source: https://habr.com/ru/post/969510/


All Articles