当前位置:网站首页>Date date calculation in shell script
Date date calculation in shell script
2022-04-23 15:39:00 【jack@london】
stay shell Script , Sometimes you need to name the file the current date date
#!/bin/sh
DATE=`date +%F`
echo "$DATE"
v_date=`date +%F`
echo "$v_date"
# Calculate the day before
v_date_ago_1=`date -d "$v_date -1 day" +%Y-%m-%d`
echo "$v_date_ago_1"
# Calculate the day before , Transformation for %F Format
v_date_ago_1=`date -d "$v_date -1 day" +%F`
echo "$v_date_ago_1"
# Day after calculation
v_date_future_1=`date -d "$v_date 1 day" +%F`
echo "$v_date_future_1"
be chmod After execution , The outputs are as follows
2022-04-21
2022-04-21
2022-04-20
2022-04-20
2022-04-22
Be careful :shell The equal sign in the script ‘=’ Before and after , No spaces .
This date counts , It can be used to clean up old backup files regularly , For example, delete 7 The day before db Backup file .
OLD_DATE=`date -d "$DATE -7 day" +%F`
rm $BCK_DIR/db_$OLD_DATE.* -f
See
Shell date Detailed command _hrbeuwhw The blog of -CSDN Blog _date shell
版权声明
本文为[jack@london]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231535553805.html
边栏推荐
- Do keyword search, duplicate keyword search, or do not match
- 网站压测工具Apache-ab,webbench,Apache-Jemeter
- What are the mobile app software testing tools? Sharing of third-party software evaluation
- PHP function
- 小程序知识点积累
- Mysql database explanation (IX)
- 时序模型:门控循环单元网络(GRU)
- 移动app软件测试工具有哪些?第三方软件测评小编分享
- Deep learning - Super parameter setting
- Cookie&Session
猜你喜欢
时序模型:门控循环单元网络(GRU)
Application of Bloom filter in 100 million flow e-commerce system
Single architecture system re architecture
Detailed explanation of kubernetes (XI) -- label and label selector
Detailed explanation of MySQL connection query
布隆过滤器在亿级流量电商系统的应用
Wechat applet customer service access to send and receive messages
KNN, kmeans and GMM
使用 Bitnami PostgreSQL Docker 镜像快速设置流复制集群
今日睡眠质量记录76分
随机推荐
Codejock Suite Pro v20. three
多级缓存使用
MySQL集群模式与应用场景
单体架构系统重新架构
Pytorch中named_parameters、named_children、named_modules函数
utils.DeprecatedIn35 因升级可能取消,该如何办
Multi level cache usage
What is CNAs certification? What are the software evaluation centers recognized by CNAs?
Mysql database explanation (IX)
Functions (Part I)
PHP function
Summary of interfaces for JDBC and servlet to write CRUD
IronPDF for .NET 2022.4.5455
c语言---字符串+内存函数
MultiTimer v2 重构版本 | 一款可无限扩展的软件定时器
Basic concepts of website construction and management
shell脚本中的DATE日期计算
Special analysis of China's digital technology in 2022
Introduction to dynamic programming of leetcode learning plan day3 (198213740)
控制结构(二)