成都创新互联网站制作重庆分公司

linux终端时钟命令,linux 终端命令

如何使用命令行更改Linux系统的日期和时间

方法一: Date 命令

成都创新互联公司专业为企业提供伊吾网站建设、伊吾做网站、伊吾网站设计、伊吾网站制作等企业网站建设、网页设计与制作、伊吾企业网站模板建站服务,10余年伊吾做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

在 Linux 中, 你可以通过 date 命令来更改系统的日期和时间:

# date --set=‘NEW_DATE’

其中 NEW_DATE 是诸如 “Sun, 28 Sep 2014 16:21:42” 或者 “2014-09-29 16:21:42” 的可读格式的日期字符串。

日期格式也可以手动指定以获得更精确的结果:

# date +FORMAT --set=‘NEW_DATE’

例如:

# date +’%Y%m%d %H%m’ --set=‘ 1518’

你也可以用相对的方式地增加或减少一定的天数,周数,月数和秒数,分钟数,小时数。 你也可以把日期和时间的参数放到一个命令中。

# date --set=‘+5 minutes’# date --set=‘-2 weeks’# date --set=‘+3 months’# date --set=‘-3 months +2 weeks -5 minutes’

最后, 把硬件时钟设置为当前系统时钟:

# hwclock --systohc

运行 hwclock --systohc 的目的是将硬件时钟同时钟同步, 这可以更正硬件时钟的系统漂移(即时钟按照一定的速度走快或走慢)。

另一方面, 如果硬件时钟是正确的, 但系统时钟有误, 可以用下面的命令更正:

# hwclock --hctosys

在两种情况下, hwclock 命令都是将两个时钟同步。 否则, 重启后时间会是错误的, 因为当电源关闭时硬件时钟会记忆时间。 然而, 这对于虚拟机器并不适用, 因为虚拟机器并不能访问硬件时钟。

方法二: NTP

另一种使系统日期和时间保持精确的方法是使用 NTP (网络时间协议)。 在 Linux 上, ntpdate 命令通过 NTP 将系统时钟和公共 NTP 服务器同步。

你可以使用如下命令来安装 ntpdate:

在 Debian 及基于 Debian 的发行版上:

# aptitude install ntpdate

在基于 Ret Hat 的发行版上:

# yum install ntpdate

使用 NTP 同步系统时钟:

# ntpdate -u 《NTP 服务器名或IP》# hwclock --systohc

除了一次性使用 ntpdate 来同步时钟, 你也可以使用 NTP 守护进程(ntpd), 它会始终在后台运行, 不断地通过 NTP 来调整系统时钟。

linux是怎么配置系统时钟的

1:使用date命令查看时区

[root@db-server ~]# date -R

Sun, 11 Jan 2015 07:10:28 -0800

[root@db-server ~]#

如上RFC 2822 format所示,上面命令输出了-0800表示西八区,是美国旧金山所在的时区,下面表示我们国家的东八区(+0800)

[root@lnx01 ~]# date -R

Sun, 11 Jan 2015 23:06:02 +0800

2:查看clock系统配置文件

[root@db-server ~]# more /etc/sysconfig/clock

ZONE="America/Los_Angeles"

UTC=true

ARC=false

如上所示,表示该系统设置的时区为“America/Los_Angeles”,也就是西八区。

Linux系统如何设置系统所在的时区呢?

方法1:使用tzselect设置时区

例子,将系统时区设置为东八区(北京时间)

[root@db-server ~]# tzselect

Please identify a location so that time zone rules can be set correctly.

Please select a continent or ocean.

1) Africa

2) Americas

3) Antarctica

4) Arctic Ocean

5) Asia

6) Atlantic Ocean

7) Australia

8) Europe

9) Indian Ocean

10) Pacific Ocean

11) none - I want to specify the time zone using the Posix TZ format.

#? 5

Please select a country.

1) Afghanistan 18) Israel 35) Palestine

2) Armenia 19) Japan 36) Philippines

3) Azerbaijan 20) Jordan 37) Qatar

4) Bahrain 21) Kazakhstan 38) Russia

5) Bangladesh 22) Korea (North) 39) Saudi Arabia

6) Bhutan 23) Korea (South) 40) Singapore

7) Brunei 24) Kuwait 41) Sri Lanka

8) Cambodia 25) Kyrgyzstan 42) Syria

9) China 26) Laos 43) Taiwan

10) Cyprus 27) Lebanon 44) Tajikistan

11) East Timor 28) Macau 45) Thailand

12) Georgia 29) Malaysia 46) Turkmenistan

13) Hong Kong 30) Mongolia 47) United Arab Emirates

14) India 31) Myanmar (Burma) 48) Uzbekistan

15) Indonesia 32) Nepal 49) Vietnam

16) Iran 33) Oman 50) Yemen

17) Iraq 34) Pakistan

#? 9

Please select one of the following time zone regions.

1) east China - Beijing, Guangdong, Shanghai, etc.

2) Heilongjiang (except Mohe), Jilin

3) central China - Sichuan, Yunnan, Guangxi, Shaanxi, Guizhou, etc.

4) most of Tibet Xinjiang

5) west Tibet Xinjiang

#? 1

The following information has been given:

China

east China - Beijing, Guangdong, Shanghai, etc.

Therefore TZ='Asia/Shanghai' will be used.

Local time is now: Sun Jan 11 23:31:51 CST 2015.

Universal Time is now: Sun Jan 11 15:31:51 UTC 2015.

Is the above information OK?

1) Yes

2) No

#? yes

Please enter 1 for Yes, or 2 for No.

#? 1

You can make this change permanent for yourself by appending the line

TZ='Asia/Shanghai'; export TZ

to the file '.profile' in your home directory; then log out and log in again.

Here is that TZ value again, this time on standard output so that you

can use the /usr/bin/tzselect command in shell scripts:

Asia/Shanghai

注意:tzselect命令只告诉你选择的时区的写法,并不会生效。所以现在它还不是东8区北京时间。你可以在.profile、.bash_profile或者/etc/profile中设置正确的TZ环境变量并导出。 例如在.bash_profile里面设置 TZ='Asia/Shanghai'; export TZ并使其生效。

[root@db-server ~]# source .bash_profile

[root@db-server ~]# date

Sun Jan 11 23:37:40 CST 2015

linux修改时间命令setdate(linux修改时间命令没权限)

1、linux修改时间命令。

2、linux修改时间命令没权限。

3、linux修改时间命令sudo。

4、linux修改时间命令setdate。

1."linux修改时间命令,为您提供linux修改时间命令图文信息,linux修改时间命令是date-s+时分秒。

2.打开并登录linux操作系统,打开终端命令窗口。

3.查看系统当前时间的命令为date。

4.使用命令date-s+时分秒来修改系统时间。

5.使用date-s+完整日期时间命令来修改linux系统的日期和时间。

linux设置系统时区命令

修改系统时间。

linux系统时钟有两个,一个是硬件时钟,即BIOS时间,就是我们进行CMOS设置时看到的时间,另一个是系统时钟,是linux系统Kernel时间。当Linux启动时,系统Kernel会去读取硬件时钟的设置,然后系统时钟就会独立于硬件运作。有时我们会发现系统时钟和硬件时钟不一致,因此需要执行时间同步,下面就分享一下时间设置及时钟同步的命令使用方法。

date命令将日期设置为2014年6月18日

----   date -s 06/18/14

将时间设置为14点20分50秒

----   date -s 14:20:50

将时间设置为2014年6月18日14点16分30秒(MMDDhhmmYYYY.ss)

----date 0618141614.30

请点击输入图片描述

hwclock/clock 命令查看、设置硬件时间

查看系统硬件时钟

hwclock  --show 或者

clock  --show

设置硬件时间

hwclock --set --date="06/18/14 14:55" (月/日/年时:分:秒)或者# clock --set --date="06/18/14 14:55" (月/日/年时:分:秒)

同步系统及硬件时钟。

下图中可以看到硬件和系统时钟相差半小时。可以使用hwclock或者clock进行同步,

硬件时钟与系统时钟同步:

# hwclock --hctosys 或者 # clock --hctosys  hc代表硬件时间,sys代表系统时间,即用硬件时钟同步系统时钟

系统时钟和硬件时钟同步:

# hwclock --systohc或者# clock --systohc  即用系统时钟同步硬件时钟

请点击输入图片描述

请点击输入图片描述

请点击输入图片描述

linux修改系统时间命令

inux修改时间命令是date-s+时分秒。

修改linux系统时间。root使用date指令:date -s

1、只修改日期,不修改时间,输入:date -s 2021-04-02。

2、只修改时间,输入:date -s 12:00:00。

3、同时修改日期时间,注意要加双引号,日期与时间之间有一空格,输入:date -s “2021-04-02 10:25:00”

4、修改完后,记得输入:clock -w。把系统时间写入CMOS修改时区不重启。在root下。

复制相应的时区文件,替换系统时区文件:

cp /usr/share/zoneinfo/主时区/次时区 /etc/localtime

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

5、文件复制命令—cp cp [参数] [源地址] [目的地址]主要参数描述如下:-a :此参数和同时指定“-dpR”参数相同 -d :在复制有符号连接的文件时,保留原始的连接。 -f :强行复制文件,不管要复制的文件是否已经存在于目标目录。 -I :覆盖现有文件之前询问用户。


本文名称:linux终端时钟命令,linux 终端命令
URL标题:http://cxhlcq.com/article/hcegeg.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部