本文目录:
- 1、ubuntu linux中怎样修改文件的“修改时间”
- 2、Ubuntu修改时区的两种方法
- 3、Ubuntu怎么修改时区?
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修改时区的两种方法
服务器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怎么修改时区?
当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修改时间】的内容来源于互联网,如引用不当,请联系我们修改。
网友留言: