与时间相关的命令(date)

时间查看命令:date

1)查看系统时间

 [root@hgg ~]# date
 
 Sat Jul 10 22:50:46 +08 2021

2)时间显示格式

date +%F

 [root@hgg ~]# date +%F
 
 2021-07-10

date " +%F %T"

 [root@hgg ~]# date "+%F %T"
 2021-07-10 22:55:17

3)修改系统实际时间

 [root@hgg ~]# date -s "1998-07-20 14:00"
  Mon Jul 20 14:00:00 +10 1998

4)显示历史的时间:

date +%F -d "-1day"

date +%F -d "1 day ago"

显示未来时间:

date +%F -d "2day"

date +%F -d "+2 day "

5)、系统自动备份数据

00:00 4月16-4月17

cp /hgg/hgg.log /log/hgg.log.$(date +F% -d "-1day")

6)、时间自动同步

[root@hgg ~]# yum install ntpdate -y

[root@hgg ~]# ntpdate ntp1.baidu.com

7)、根据时间批量删除信息

01、查找7天前的数据

find /hgg -type f -mtime +7

02、查找最近七天的数据

find /hgg -type f -mtime -7

posted @ 2022-01-08 16:13  Yusir-SRE  阅读(104)  评论(0编辑  收藏  举报