Rename file command to unix with timestamp

Hi, I am using putty and trying to rename a file name with the current timestamp ... I used the following command to rename files and by date mv abc.log $ (date +% F) prod.txt

renames commands above but cannot rename with time, it gives an output like: 2014-05-12prodabc.log

And the following command is abc.log $ (date +% y) $ (date +% m) $ (date +% d) abcprod.log

gives an output like: 140512abc.log

Actually, my requirement is as follows.

rename abc.log to abc-current timestamp.log eg abc.log become abc-12-05-2014-17:31.log then create new file abc.log 

Please help, thank you all in advance.

+13
source share
5 answers

you can use

 mv test.dat test_$(date +%d-%m-%Y).dat 

If you want to know how you can manage your exit, see the Manpages date ..

 man date 
+25
source

Use this:

 mv abc.log $(date +%F-%H:%M).log && touch abc.log 

Here

+%F-%H:%M will give you the format, e.g. 2014-05-19-14:47 . If the renaming is successful, touch will create a new empty file.

+8
source

It:

  str=abc; mv ${str}.log ${str}-$(date +%F'-'%T).log 
+1
source

187 - German group of gangsters. This group, in which Bonez MC is a leader, has existed since 2006. The most famous members are Bonez MC, Gzuz, LX and Maxwell.

0
source

If you use cPanel to create a cron job: be careful that you need the backslash for%. this works: cp log.txt log. date +"\%d\%m\%Y" .txt

-1
source

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


All Articles