Linux系统的时间管理

1 查看系统时间和日期 :date

[[email protected] Desktop]# date 
Tue Jun  2 05:25:05 EDT 2015

2查看硬件时间:hwclock --show | -r

[[email protected] Desktop]# hwclock 
Tue 02 Jun 2015 05:40:30 AM EDT  -0.272377 seconds

3 修改系统时间使用的命令:

修改系统时间:

[[email protected] named]# date -s "6/1/2015 18:00:00" #设置为6月/1日/2015年 时:分:秒
Mon Jun  1 18:00:00 EDT 2015
[[email protected] named]# date -s "11:11:11 2011-10-3" #这样也行
Mon Oct  3 11:11:11 CST 2011

修改系统硬件时间:

[[email protected] Desktop]# hwclock --set --date="06/18/14 14:55" 
[[email protected] Desktop]# hwclock -r   ##相当于hwclock --show
Wed 18 Jun 2014 02:55:22 PM EDT  -0.569262 seconds

4 将当前系统的时间和日期写入BIOS,避免重启后失效 : hwclock -w

[[email protected] Desktop]# hwclock -w

注意:

hwclock

##将系统时间设置为当前硬件的时间

-s, --hctosys   set the system time from the hardware clock

##将硬件的时间设置为当前系统的时间

-w, --systohc   set the hardware clock from the current system time

5 时区的更改:tzselect

tzselect 只是提示我们去选择时区,实际上不会生效,但我们可以根据提示去操作。

[[email protected] Desktop]# 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:Wed Jun  3 09:31:59 CST 2015.
Universal Time is now:Wed Jun  3 01:31:59 UTC 2015.
Is the above information OK?
1) Yes
2) 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

根据后面的提示,需要将 TZ=‘Asia/Shanghai‘; export TZ 这一行写入到.profile配置文件中,不过我习惯写在.bashrc文件中。

[[email protected] ~]# vim /root/.bash_profile ##编辑当前用户的bash环境文件
[[email protected] ~]# cat /root/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
TZ=‘Asia/Shanghai‘; export TZ   ##将时区更改的语句 放到这里

建议把时区设置写在/etc/bashrc这个文件中,全局生效。

查看当前的时区:

[[email protected] Desktop]# date -R
Tue, 02 Jun 2015 22:09:31 -0400

刷新重读一下.bash_profile

[[email protected] Desktop]# date -R
Tue, 02 Jun 2015 22:14:49 -0400
[[email protected] Desktop]# source /root/.bash_profile 
[[email protected] Desktop]# date -R

Wed, 03 Jun 2015 10:15:10 +0800 ##时区已更改为北京时区

另一种方法:直接修改配置文件

时区的配置文件:/etc/localtime

所有时区文件的存放路径:/usr/share/zoneinfo

亚洲时区:/usr/share/zoneinfo/Asia

选择上海时区:/usr/share/zoneinfo/Asia/Shanghai

将上海时区的文件软件链接到时区的配置文件/etc/localtime

[[email protected] /]# ln -s /usr/share/zoneinfo/Asi a/Shanghai  /etc/localtime

重启之后查看date -R

图形界面:

redhat 6以下:system-config-time

redhat 7:system-config-date

时间: 2024-07-30 12:59:48

Linux系统的时间管理的相关文章

Linux系统的时间管理及优化

一直以来对Linux下的时间管理知之不详,GFree_wind在微博发起过几次Linux下时钟的讨论,和Godbach这些大牛比,我完全插不上话,因为不懂.近来闲暇时间研究了下Linux下的时间管理,分享出来,请大家指正.   从我们大白话的角度想,时间管理其实分成两部分,就像我们小时候学习物理的时候物理老师不断强调时间和时刻的区别.一个是时刻,比如现在是20:44:37秒,指的是时刻,我们手机上看时间,指的也是时刻.另一块是时间,比如说,我每天工作八小时,再比如说,半小时之后,我要出门了,结束

Linux系统软件包的管理   3月30日课程

Linux系统软件包的管理 一. rpm工具 rpm Redhat Package Manager, 设计理念是开放的,不仅仅是在RedHat平台上,在SUSE上也是可以使用的. rpm包名字构成由-和.分成了若干部分,如abrt-cli-2.0.8-15.el6.centos.i686.rpm, abrt-cli:是包名 2.0.8-15:是版本号 el6:指的是redhat企业版6 centos:指的是这是在centos上用的 i686:指的是平台类型 有些rpm包并没有写具体的平台而是no

Linux系统的磁盘管理及分区应用

要求: 第一部分:磁盘分区 1)为虚拟机添加一块80GB.SCSI接口的硬盘 2)划分2个10GB的EXT4主分区,剩余的作为扩展分区 3)划分一个2G的swap交换分区 4)划分一个10G的FAT32的VFAT逻辑分区 第二部分:新磁盘分区的应用 a)将系统中的普通用户king的宿主目录迁移到所添加的新硬盘的其中一个主分区上 并能实现开机自动挂载,不影响开机时用户king的正常登陆(修改fstab配置文件) b)实现新添加交换分区的开机自动挂载(修改fstab配置文件) c)实现先添加另一个主

linux系统校正时间

linux系统校正时间 cp /etc/localtime /etc/localtime.bak cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime ntpdate pool.ntp.org hwclock --systohc 通过ntp服务,自动获取网络时间并同步 定时校正服务器时间 # yum install –y ntp   //安装ntp服务 # crontab -e       //打开linux定时计划任务 0 23 * * * /

如何在 systemd 下管理Linux系统的时间和日期

timedatectl是用来查询和修改系统时间和配置的Linux应用程序.它是 systemd 系统服务管理 的一部分,并且允许你检查和修改系统时钟的配置. 在这篇文章中,我们将涉及该小巧但十分重要应用程序的所有方面. 系统当前的时间状态 想要查看系统当前日期/时间,以及可使用不带任何参数的命令查看当前系统时间配置,可以这样: # timedatectl 输入的结果就像这样: 修改日期 想要修改系统日期,你可以简单地使用timedatectl设置时间命令,紧随命令的是YYYY-MM-DD格式的日

linux下的时间管理概述

2017/6/21 时间这一概念在生活中至关重要,而在操作系统中也同样重要,其在系统中的功能绝不仅仅是给用户提供时间这么简单,内核的许多机制都依赖于时间子系统.但凡是要在某个精确的时间执行某个事件,必然会用到时间子系统.而内核中定时器的发展可以以2.6版本的内核作为一个分界点.之前主要是低分辨率定时器,2.6开发期间便引入了高分辨率定时器.分辨率的高低意味着时间粒度的大小. 本节重点介绍下涉及到的几个重点概念 时钟设备 周期时钟/动态时钟 高分辨率/低分辨率 定时器 时钟设备时钟设备算是最低层的

linux系统的日常管理2

linux系统的任务计划 crond命令简介 crond是linux下用来周期性的执行某种任务或等待处理某些事件的一个守护进程,与windows下的计划任务类似,当安装完成操作系统后,默认会安装此服务工具,并且会自动启动crond进程,crond进程每分钟会定期检查是否有要执行的任务,如果有要执行的任务,则自动执行该任务. Linux下的任务调度分为两类,系统任务调度和用户任务调度. 系统任务调度:系统周期性所要执行的工作,比如写缓存数据到硬盘.日志清理等.在/etc目录下有一个crontab文

保证Linux系统安全——账号管理

不管是Windows操作系统还是Linux操作系统,想要登录系统必须要有合法的账户及密码.本篇博文主要介绍Linux系统下的账户信息. 博文大纲:一.Linux系统的账号及群组1.UID与GID:2.使用者账号:(1)/etc/passwd文件结构:(2)/etc/shadow文件结构:3.有效群组与初始群组:(1)/etc/group文件结构:(2)有效群组与初始群组:(3)/etc/gshadow文件结构:二.账号管理指令:(1)useradd命令(2)passwd命令(3)chage命令(

Linux系统程序包管理

Linux程序包管理 API:Application Program Interface ABI:Application Binary INnterface Unix-like,系统上的二级制格式的应用程序文件格式为 ELF Windows系统的二级制格式的应用程序文件格式为: exe,msi 库级别的虚拟化: Linux:WinE,可以实现在Linux系统上运行Windows的二进制可执行程序 Windows:Cywin,可以实现在Windows系统上运行Linux的位二进制可执行程序 各种编