How to change Date, Time , Timezone and Hardware Clock (Real Time Clock RTC) in linux from command line (cli)

Date command will display your current date time with time zone.

date
Fri Apr 21 13:59:49 IST 2016

To change date and time

date -s "21APR2017 10:06:00"

To change only date

date +%Y%m%d -s "20170421"

To change only time

date +%T -s "11:14:00"

How to change time zone
First take backup of existing localtime file

cp /etc/localtime /backup/localtime_backup

Copy and overwrite existing /etc/localtime file by selecting your prefer timezone file which present in /usr/share/zoneinfo/ directory. eg. I want set timezone to Kolkata.

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

Hardware clock know as Real Time Clock (RTC)

hwclock

If hardware clock is different timezone from system timezone then edit file /etc/sysconfig/clock.

vi /etc/sysconfig/clock 

update below timezone

ZONE="Asia/Kolkata"
UTC=true
ARC=false

you can also set using cli.

hwclock --set --date "21 Oct 2017 21:17" --IST

Then verify both time zone system as well as hardware type

date
hwclock

note: It is always advised to reboot the system after changing date time or time zone because some of the services currently running will be holding old time. eg. cronjob, MySQL.

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
kurtpritchard Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
kurtpritchard
Guest
kurtpritchard

Hello. Great job.
Thanks!