{"id":3734,"date":"2014-11-17T07:55:24","date_gmt":"2014-11-16T23:55:24","guid":{"rendered":"http:\/\/rmohan.com\/?p=3734"},"modified":"2014-11-17T07:55:24","modified_gmt":"2014-11-16T23:55:24","slug":"hostnamectl-and-timedatectl-and-date-and-hwclock","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=3734","title":{"rendered":"hostnamectl  and timedatectl  and date and HWCLOCK"},"content":{"rendered":"<p>Modify CentOS 7 hostname<\/p>\n<p>In CentOS, there are three definitions hostname: static (static), transient (transient), and flexible (pretty). &#8220;Static&#8221; host name is also called kernel hostname, is the system at boot time from \/etc\/hostname<br \/>\nautomatic initialization of the host name. &#8220;Transient&#8221; host name is in the system is running temporarily assigned host name, for example, assigned by DHCP or mDNS server.<br \/>\nStatic hostname and transient hostname comply with the same character as the Internet domain restriction rules. On the other hand, a &#8220;flexible&#8221; is allowed to use<br \/>\nthe hostname of free-form (including special \/ whitespace) host name, to show to the end user (eg Linuxidc).<\/p>\n<p>In CentOS 7, a man named hostnamectl command-line tool that allows you to view or modify the host name associated with the configuration.<\/p>\n<p>[root@keeplive ~]# hostnamectl<br \/>\n   Static hostname: keeplive<br \/>\n         Icon name: computer<br \/>\n           Chassis: n\/a<br \/>\n        Machine ID: 2b48dba259f2428ca8038f7aeb1d7f15<br \/>\n           Boot ID: 57772bec11854cd08ee72db54a1441d3<br \/>\n    Virtualization: vmware<br \/>\n  Operating System: CentOS Linux 7 (Core)<br \/>\n       CPE OS Name: cpe:\/o:centos:centos:7<br \/>\n            Kernel: Linux 3.10.0-123.9.3.el7.x86_64<br \/>\n      Architecture: x86_64<br \/>\n[root@keeplive ~]# hostnamectl status<br \/>\n   Static hostname: keeplive<br \/>\n         Icon name: computer<br \/>\n           Chassis: n\/a<br \/>\n        Machine ID: 2b48dba259f2428ca8038f7aeb1d7f15<br \/>\n           Boot ID: 57772bec11854cd08ee72db54a1441d3<br \/>\n    Virtualization: vmware<br \/>\n  Operating System: CentOS Linux 7 (Core)<br \/>\n       CPE OS Name: cpe:\/o:centos:centos:7<br \/>\n            Kernel: Linux 3.10.0-123.9.3.el7.x86_64<br \/>\n      Architecture: x86_64<br \/>\n[root@keeplive ~]# hostnamectl &#8211;static<br \/>\nkeeplive<br \/>\n[root@keeplive ~]# hostnamectl &#8211;transient<br \/>\nkeeplive<br \/>\n[root@keeplive ~]# hostnamectl &#8211;pretty<\/p>\n<p>timedatectl<\/p>\n<p>How to display the current date and time using timedatectl ?<\/p>\n<p>[root@keeplive ~]# timedatectl<br \/>\n      Local time: Mon 2014-11-17 07:50:53 SGT<br \/>\n  Universal time: Sun 2014-11-16 23:50:53 UTC<br \/>\n        RTC time: Sun 2014-11-16 23:50:53<br \/>\n        Timezone: Asia\/Singapore (SGT, +0800)<br \/>\n     NTP enabled: yes<br \/>\nNTP synchronized: yes<br \/>\n RTC in local TZ: no<br \/>\n      DST active: n\/a<\/p>\n<p>How to change the current date using timedatectl ?<\/p>\n<p>timedatectl set-time YYYY-MM-DD<\/p>\n<p>Example of change the current date :<br \/>\n[root@centos7 ~]# timedatectl set-time 2014-11-17<\/p>\n<p>How to change the current time using timedatectl ?<br \/>\ntimedatectl set-time HH:MM:SS<\/p>\n<p>Example of change the current time :<br \/>\n[root@centos7 ~]# timedatectl set-time 00:50:00<\/p>\n<p>[root@keeplive ~]# timedatectl list-timezones | grep Asia<br \/>\nAsia\/Aden<br \/>\nAsia\/Almaty<br \/>\nAsia\/Amman<br \/>\nAsia\/Anadyr<br \/>\nAsia\/Aqtau<br \/>\nAsia\/Aqtobe<br \/>\nAsia\/Ashgabat<br \/>\nAsia\/Baghdad<br \/>\nAsia\/Bahrain<br \/>\nAsia\/Baku<br \/>\nAsia\/Bangkok<br \/>\nAsia\/Beirut<br \/>\nAsia\/Bishkek<br \/>\nAsia\/Brunei<br \/>\nAsia\/Chita<br \/>\nAsia\/Choibalsan<br \/>\nAsia\/Colombo<br \/>\nAsia\/Damascus<br \/>\nAsia\/Dhaka<br \/>\nAsia\/Dili<br \/>\nAsia\/Dubai<br \/>\nAsia\/Dushanbe<br \/>\nAsia\/Gaza<br \/>\nAsia\/Hebron<br \/>\nAsia\/Ho_Chi_Minh<br \/>\nAsia\/Hong_Kong<br \/>\nAsia\/Hovd<br \/>\nAsia\/Irkutsk<br \/>\nAsia\/Jakarta<br \/>\nAsia\/Jayapura<br \/>\nAsia\/Jerusalem<br \/>\nAsia\/Kabul<br \/>\nAsia\/Kamchatka<br \/>\nAsia\/Karachi<br \/>\nAsia\/Kathmandu<br \/>\nAsia\/Khandyga<br \/>\nAsia\/Kolkata<br \/>\nAsia\/Krasnoyarsk<br \/>\nAsia\/Kuala_Lumpur<br \/>\nAsia\/Kuching<br \/>\nAsia\/Kuwait<br \/>\nAsia\/Macau<br \/>\nAsia\/Magadan<br \/>\nAsia\/Makassar<br \/>\nAsia\/Manila<br \/>\nAsia\/Muscat<br \/>\nAsia\/Nicosia<br \/>\nAsia\/Novokuznetsk<br \/>\nAsia\/Novosibirsk<br \/>\nAsia\/Omsk<br \/>\nAsia\/Oral<br \/>\nAsia\/Phnom_Penh<br \/>\nAsia\/Pontianak<br \/>\nAsia\/Pyongyang<br \/>\nAsia\/Qatar<br \/>\nAsia\/Qyzylorda<br \/>\nAsia\/Rangoon<br \/>\nAsia\/Riyadh<br \/>\nAsia\/Sakhalin<br \/>\nAsia\/Samarkand<br \/>\nAsia\/Seoul<br \/>\nAsia\/Shanghai<br \/>\nAsia\/Singapore<br \/>\nAsia\/Srednekolymsk<br \/>\nAsia\/Taipei<br \/>\nAsia\/Tashkent<br \/>\nAsia\/Tbilisi<br \/>\nAsia\/Tehran<br \/>\nAsia\/Thimphu<br \/>\nAsia\/Tokyo<br \/>\nAsia\/Ulaanbaatar<br \/>\nAsia\/Urumqi<br \/>\nAsia\/Ust-Nera<br \/>\nAsia\/Vientiane<br \/>\nAsia\/Vladivostok<br \/>\nAsia\/Yakutsk<br \/>\nAsia\/Yekaterinburg<br \/>\nAsia\/Yerevan<br \/>\n[root@keeplive ~]#<\/p>\n<p>In order to change the time zone to Asia\/Kuala_Lumpur, type the following command as a root user :<br \/>\n[root@centos7 ~]# timedatectl set-timezone Asia\/Singapore<\/p>\n<p>date Utility<\/p>\n<p>The date utility is available on all Linux systems. date allows you to display and change the current date and time and it is frequently used in scripts to display the system clock.<\/p>\n<p>2.1. How to display the current Date and Time using date ?<\/p>\n<p>To display the current date and time, run the date command with no additional command line options:<br \/>\n[root@centos7 ~]# date<br \/>\nTue Nov  4 01:12:39 MYT 2014<\/p>\n<p>This displays the day of the week followed by the current date, local time, abbreviated time zone, and year.<\/p>\n<p>2.2. How to display the current Date and Time in customized the format ?<\/p>\n<p>You can also customize the format of the displayed information by providing the +\u201dformat\u201d option on the command line:<br \/>\ndate +&#8221;format&#8221;<\/p>\n<p>Example :<br \/>\n[root@centos7 ~]# date +&#8221;%Y-%m-%d %H:%M&#8221;<br \/>\n2014-11-17 01:20<\/p>\n<p>2.3. How to change the current time using date ?<\/p>\n<p>In order to change the current date and time, type the date command with the \u2013set or -s option as a root user :<\/p>\n<p>To change the current time, run the date command with the \u2013set or -s option as root:<br \/>\ndate +%T -s HH:MM:SS<\/p>\n<p>Replace HH with an hour, MM with a minute, and SS with a second, all typed in a two-digit form.<\/p>\n<p>As an example change the current time to 11:56 p.m., as a root, run the following command :<br \/>\n[root@centos7 ~]# date +%T &#8211;set 23:56:00<\/p>\n<p>[root@keeplive ~]# hwclock<br \/>\nMon 17 Nov 2014 07:54:18 SGT  -0.396692 seconds<br \/>\n[root@keeplive ~]#<\/p>\n<p>How to change the current Date and Time using hwclock ?<\/p>\n<p>In order to change the hardware clock date and time, you can do so by appending \u2013set and \u2013date options along with your specification:<br \/>\nhwclock &#8211;set &#8211;date &#8220;dd mmm yyyy HH:MM&#8221;<\/p>\n<p>As an example, if we want to set the date and time to to \u201c15:20, October 29, 2015?, run the command in the following format:<br \/>\n[root@centos7 ~]# hwclock &#8211;set &#8211;date &#8220;29 Oct 2015 15:20&#8221;<\/p>\n<p>3.2. How to change the current Date and Time using hwclock ?<\/p>\n<p>In order to change the hardware clock date and time, you can do so by appending \u2013set and \u2013date options along with your specification:<br \/>\nhwclock &#8211;set &#8211;date &#8220;dd mmm yyyy HH:MM&#8221;<\/p>\n<p>As an example, if we want to set the date and time to to \u201c15:20, October 29, 2015?, run the command in the following format:<br \/>\n[root@centos7 ~]# hwclock &#8211;set &#8211;date &#8220;29 Oct 2015 15:20&#8221;<\/p>\n<p>Note : In Red Hat Enterprise Linux 6 \/ CentOS 6, the hwclock command was run automatically on every system shutdown or reboot, but it is not in Red Hat Enterprise Linux 7 \/CentOS 7.<\/p>\n<p>For more information on how to configure the date and time in Red Hat Enterprise Linux 7 and CentOS 7, please read the manual page for the timedatectl, date and hwclock.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Modify CentOS 7 hostname<\/p>\n<p>In CentOS, there are three definitions hostname: static (static), transient (transient), and flexible (pretty). &#8220;Static&#8221; host name is also called kernel hostname, is the system at boot time from \/etc\/hostname automatic initialization of the host name. &#8220;Transient&#8221; host name is in the system is running temporarily assigned host name, for example, [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4,17],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/3734"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3734"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/3734\/revisions"}],"predecessor-version":[{"id":3735,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/3734\/revisions\/3735"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3734"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3734"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3734"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}