linux时间设置

仅供学习

修改linux的系统时间的方法:
1、利用date命令设定系统的日期与时间,语法“date -s “年月日 时:分秒””;
2、执行“hwclock --systohc”命令保存设置,关机重启。

本教程操作环境:linux5.9.8系统、Dell G3电脑。
Linux下修改系统时间
在Linux中,可以利用date命令修改系统时间。
date命令可以用来显示或设定系统的日期与时间。
比如说把时间设为2021-07-12 18:30:50,我们可以先设日期
1
date -s 20210712
再设时间
1
date -s 18:30:50
也可以一步到位,直接使用一下命令
1
date -s"20210712 18:30:50"
时间设置完了就要保存了。如果你会正常关机还好说。系统关的时候会保存一次,可是如果你可能不正常关机的话,可以这么先保存一下设置
1
hwclock --systohc
对的,是这么写。网上大多的写法是
1
clock -w
或者
1
hwclock -w
而你仔细分析下就知道,clock是hwclock的软链接。而hwclock的help和man里根本未提-w这个参数。不知道-w是哪年的写法。

  • 3
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Linux系统中的时间设置配置文件是/etc/chrony.conf。可以通过编辑该文件来配置时间服务器和客户端的时间同步。具体步骤如下: 1. 查看/etc/chrony.conf文件,可以使用以下命令: ```shell cat /etc/chrony.conf ``` 2. 编辑/etc/chrony.conf文件,可以使用以下命令: ```shell vi /etc/chrony.conf ``` 3. 在/etc/chrony.conf文件中,可以进行以下配置: - 取消网络服务器作为时间同步源的配置,添加本地时间服务器。 - 设置允许与时间服务器同步时间的客户端网段。 - 设置时间服务器允许使用本地时间作为标准时间进行同步。 例如,以下是一个简单的/etc/chrony.conf文件配置示例: ```shell # Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). server 0.centos.pool.ntp.org iburst server 1.centos.pool.ntp.org iburst server 2.centos.pool.ntp.org iburst server 3.centos.pool.ntp.org iburst # Ignore stratum in source selection. stratumweight 0 # Record the rate at which the system clock gains/losses time. driftfile /var/lib/chrony/drift # Enable kernel RTC synchronization. rtcsync # In first three updates step the system clock instead of slew makestep 1 -1 # Allow NTP client access from local network. allow 192.168.0.0/16 # Serve time even if not synchronized to a time source. local stratum 10 # Specify file containing keys for NTP authentication. keyfile /etc/chrony.keys # Specify directory for log files. logdir /var/log/chrony ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值