包含ubuntu修改时间的词条

2023-11-19 0 548

目录:

Ubuntu修改时区的两种方法

服务器date时间不准:

jingke@ubuntu:~# date

Tue, 05 Nov 2019 21:08:31 -0500

实际是下午9点

  第一步:执行tzselect

修改/etc/localtime文件

控制系统时区的文件是/etc/localtime。只要把这个文件复制成相应时区的文件,系统时区就改成相应的时间了。

时区信息在:/usr/share/zoneinfo里。比如需要把本机 时区改成Shanghai的时间:

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

ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

这两条指令都可以更改。

使用date查看时间

                                                 第二种修改方式 timedatectl

1.查看当前时间状态

查看当前时间状态 timedatectl status :

wxs@ubuntu:~/6-1/task4$ timedatectl status

      Local time: Tue 2017-11-07 18:14:30 PST

  Universal time: Wed 2017-11-08 02:14:30 UTC

        RTC time: Wed 2017-11-08 02:14:29

      Time zone: America/Los_Angeles (PST, -0800)

Network time on: yes

NTP synchronized: yes

RTC in local TZ: no

系统显示的时间是错误的,错误原因也是显而易见的,使用的是America/Los_Angeles的时区。

因此只要修改时区就能保证时间的正确。

2.修改时区

所有的时区名称存储在/usr/share/zoneinfo文件中。

执行命令timedatectl set-timezone “Asia/Shanghai” 就可以将时区设为上海时区。

==== AUTHENTICATING FOR org.freedesktop.timedate1.set-timezone ===

Authentication is required to set the system timezone.

Authenticating as: wxs,,, (wxs)

Password:

==== AUTHENTICATION COMPLETE ===12345

重新查看当前时间状态 timedatectl status :

wxs@ubuntu:~/6-1/task4$ timedatectl status

      Local time: Wed 2017-11-08 10:15:45 CST

  Universal time: Wed 2017-11-08 02:15:45 UTC

        RTC time: Wed 2017-11-08 02:15:45

      Time zone: Asia/Shanghai (CST, +0800)

Network time on: yes

NTP synchronized: yes

RTC in local TZ: no12345678

此时时间已经正常了。

Ubuntu 时区和自动校时设置

    tzselect

    sudorm-rf /etc/localtime

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

该方式为一天更新一次。

    sudo apt-get install -y ntpdate #安装

    sudo vim /etc/cron.daily/ntpdate                #添加下面一行,每天同步。

    sudo ntpdate ntp.ubuntu.com cn.pool.ntp.org

    sudo chmod 755 /etc/cron.daily/ntpdate          #修改权限

    sudo ntpdate -d cn.pool.ntp.org                #立即同步时间

该方式为连续定时更新

    apt-getinstall -y ntpd#安装

    vim /etc/ntp.conf#添加下面一行

    server cn.pool.ntp.org

    /etc/init.d/ntp restart#重启

如何修改Ubuntu Linux的时间

可以使用date命令来修改系统时间,再使用hwclock –systohc写入硬件,示例如下

例如将时间设置为 2015-06-15 13:30,按如下命令操作:

# sudo date -s “2015-06-15 13:30”

# sudo hwclock –systohc

date命令

date命令是显示或设置系统时间与日期。

很多shell脚本里面需要打印不同格式的时间或日期,以及要根据时间和日期执行操作。延时通常用于脚本执行过程中提供一段等待的时间。日期可以以多种格式去打印,也可以使用命令设置固定的格式。在类UNIX系统中,日期被存储为一个整数,其大小为自世界标准时间(UTC)1970年1月1日0时0分0秒起流逝的秒数。

语法

date(选项)(参数)

选项

-d字符串:显示字符串所指的日期与时间。字符串前后必须加上双引号;

-s字符串:根据字符串来设置日期与时间。字符串前后必须加上双引号;

-u:显示GMT;

–help:在线帮助;

–version:显示版本信息。

参数

+时间日期格式:指定显示时使用的日期时间格式。

日期格式字符串列表

%H 小时,24小时制(00~23)

%I 小时,12小时制(01~12)

%k 小时,24小时制(0~23)

%l 小时,12小时制(1~12)

%M 分钟(00~59)

%p 显示出AM或PM

%r 显示时间,12小时制(hh:mm:ss %p)

%s 从1970年1月1日00:00:00到目前经历的秒数

%S 显示秒(00~59)

%T 显示时间,24小时制(hh:mm:ss)

%X 显示时间的格式(%H:%M:%S)

%Z 显示时区,日期域(CST)

%a 星期的简称(Sun~Sat)

%A 星期的全称(Sunday~Saturday)

%h,%b 月的简称(Jan~Dec)

%B 月的全称(January~December)

%c 日期和时间(Tue Nov 20 14:12:58 2012)

%d 一个月的第几天(01~31)

%x,%D 日期(mm/dd/yy)

%j 一年的第几天(001~366)

%m 月份(01~12)

%w 一个星期的第几天(0代表星期天)

%W 一年的第几个星期(00~53,星期一为第一天)

%y 年的最后两个数字(1999则是99)

Ubuntu怎么手动修改时间

方法/步骤 1 打开ubuntu14.04左侧,系统设置 2 进入系统设置后,找到“系统”,选择“时间日期” 3 修改位置信息 4 勾寻手动”,设置时间 5 设置时钟样式 6 打开终端ctrl+alt+t,分别输入date,验证时间是否设置正确;输入cal,验证日期是否设置正确。…

Ubuntu怎么修改时区?

当Linux启动时,系统Kernel会去读取硬件时钟的设置,系统时钟就会独立于硬件运作。

linux系统时钟有两个,一个是硬件时钟,即BIOS时间,就是我们进行CMOS设置时看到的时间,另一个是系统时钟,是linux系统Kernel时间。

2.同步系统及硬件时钟,硬件和系统时钟相差半小时,可以使用hwclock或者clock进行同步。

3.设置,开始设置时区时,参考网上的资料,使用tzselect 命令来进行,结果发现tzselect命令只是告诉了设置时区的方法,而并不是真的去修改/etc/sysconfig/clock这个文件。

4.如何使用tzselect命令设置时区,以及如何通过修改/etc/sysconfig/clock配置文件来设置时区。

5.行完tzselect命令选择时区后,时区并没有更改,只是在命令最后提示你可以执行。

6.TZ=’Asia/Shanghai’; export TZ 并将这行命令添加到.profile中,然后退出并重新登录。

ubuntu linux中怎样修改文件的“修改时间”

现在我们新建一个空白文件ubuntugege.txt,看到当前的文件访问时间和修改时间是一样的。

用以下命令进行修改:

touch -m -d “2000-01-01 10:10:10” ubuntugege.txt

嘿,文件修改时间变成了2000-01-01 10:10:10,这下我们也做了个小小的穿越呀!

当然,这个命令还有更多其它高级的用法,比如:你可以读取一个已存在的文件的修改时间再修改到指定的文件上,相当于复制“修改时间”到别的文件上,大家运行touch –help查看手册。

用法:touch [选项]… 文件…Update the access and modification times of each FILE to the current time.A FILE argument that does not exist is created empty, unless -c or -his supplied.A FILE argument string of – is handled specially and causes touch tochange the times of the file associated with standard output.Mandatory arguments to long options are mandatory for short options too. -a 只更改访问时间 -c, –no-create 不创建任何文件 -d, –date=字符串 使用指定字符串表示时间而非当前时间 -f (忽略) -h, –no-dereference 会影响符号链接本身,而非符号链接所指示的目的地 (当系统支持更改符号链接的所有者时,此选项才有用) -m 只更改修改时间 -r, –reference=FILE use this file’s times instead of current time -t STAMP use [[CC]YY]MMDDhhmm[.ss] instead of current time –time=WORD change the specified time: WORD is access, atime, or use: equivalent to -a WORD is modify or mtime: equivalent to -m –help 显示此帮助信息并退出 –version 显示版本信息并退出请注意,-d 和-t 选项可接受不同的时间/日期格式。

【ubuntu修改时间】的内容来源于互联网,若引用不当,请发邮件456(@)456.cn联系删除

相关文章

猜你喜欢
官方客服团队

为您解决烦忧 - 24小时在线 专业服务

  • 0 +

    访问总数

  • 0 +

    会员总数

  • 0 +

    文章总数

  • 0 +

    今日发布

  • 0 +

    本周发布

  • 4975 +

    运行天数

你的前景,远超我们想象