It's simple, but I always forget it, so I'll write it down.
If you want to add today's date and time to the file name when you run the shell and back up the file, remember the following and put it in the shell script so that you do not have to change the date every time.
Outputs the Christian era date without partitions.
$(date "+%Y%m%d")
Output example
% echo $(date "+%Y%m%d")
20200316
Outputs the time to date and seconds in the Christian era without partitions.
$(date "+%Y%m%d%H%M%S")
Output example
% echo $(date "+%Y%m%d%H%M%S")
20200316122346
Example with dividers such as slashes and semicolons
$(date "+%Y/%m/%d-%H:%M:%S")
Output example
% echo $(date "+%Y/%m/%d-%H:%M:%S")
2020/03/16-12:24:45
that's all
Recommended Posts