linux系统时钟控制

一、查看及设置日期时间

1.查看日期时间

date查看日期时间

−格式:date +"显示格式"

−显示格式中可以添加字符串,使用特定%变量(若用在crontab记录中应使用\%)

[root@hadoop ~]# date
Sun May  1 02:08:04 CST 2022    //默认格式显示
[root@hadoop ~]# date +"%Y-%m-%d %H:%M"
2022-05-01 02:10    //提取日期时刻

在文件名中嵌入日期时间信息

−命令替换机制:$(命令行) 

[root@hadoop ~]# touch file-$(date +%Y%m%d).txt    //文件名嵌入当天日期
[root@hadoop ~]# ls file*
file1  file{1..5.txt}  file1.txt  file2  file-20220501.txt

2.设置日期时间

date设置日期时间

−用法1:date mmddHHMMYYYY

−用法2:date -s "YYYY-mm-ddHH:MM"

[root@hadoop ~]# date -s "2022-08-15 20:18"    //更改日期时间
Mon Aug 15 20:18:00 CST 2022
[root@hadoop ~]# date    //确认结果
Mon Aug 15 20:18:03 CST 2022

二、硬件时钟调校

1.校对系统时钟

以主板BIOS时钟为标准,重设系统时钟

−hwclock-s

−或者hwclock--hctosys

[root@hadoop ~]# date
Mon Aug 15 20:19:11 CST 2022
[root@hadoop ~]# hwclock -s    //重设为BIOS硬件时钟
[root@hadoop ~]# date    /确认结果
Mon Aug 15 20:19:45 CST 2022

2.校对BIOS硬件时钟

以系统时钟为标准,重设主板BIOS的硬件时钟

−hwclock-w

−或者hwclock--systohc

[root@hadoop ~]# date -s'2022-08-15 20:22'    //先设置准确系统时钟
Mon Aug 15 20:22:00 CST 2022
[root@hadoop ~]# hwclock -w    //校对BIOS硬件时钟

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lambda-小张

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值