Gitlab backup files are displayed in timestamps, similar to: 1438624820_gitlab_backup.tar to make it easier toread, you want to convert the file name to a date format:2015-08-04_gitlab_ Backup.tar
So I looked for the method of time conversion in the shell and recorded the following memo.
Some commands for Linux under time conversion:
- Date +%s can get Unix timestamp;
- Use the shell to turn the date time and timestamp to each other:
date-d "2015-08-04 00:00:00" +%s output:1438617600
- And the time stamp is converted to a string to do this:
date-d @1438617600 "+%y-%m-%d" output:2015-08-04
- If you need to get the days before and after the specified date:
Seconds= ' date-d "2015-08-04 00:00:00" +%s ' #得到时间戳
seconds_new= ' expr $seconds + 86400 ' #加上一天的秒数86400
date_new= ' date-d @ $seconds _new "+%y-%m-%d" ' #获得指定日前加上一天的日前
To modify the script for the Gitlab backup file name:
Shell date-time and timestamp conversions