I have to create a file with the name X.<current_date_and_time>_<time in HHMM> where the time is 3 minutes hence the time now

for example: If the current date is 9/17/2016 and current time is 14.21 filename should be: X.20160917.1421_1424

command I am using for this is:

mv sample.xml A$(date +%Y%m%d.%H%M)_$((date +%H%M)+ 3m)

It's not working because of including + 3m.


Assuming GNU date(1):

mv sample.xml A"$(date +%Y%m%d.%H%M)_$(date -d 'now +3 minutes' +%H%M)"
| improve this answer | |
  • This is accurately working. Thanks Sato Katsura! – rachit7 Sep 17 '16 at 10:18

With dateutils

dateadd --format '%H%M' --zone 'Your/Time Zone' now +3m
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.