Set Date, Time, Time Zone Change from Command Line in Linux
In this article we will set Linux time, set date, hardware clock, change timezone from command line.
Linux Current Date And Time
Get current date and time:
# date
Output:
Fri Feb 8 16:59:38 PST 2019
Set date from the command line:
# date +%Y%m%d -s "20190208"
Set time from the command line
# date +%T -s "09:21:34"
Set time and date from the command line:
# date -s "08 FEB 2019 05:23:34"
Set Hardware Clock
hwclock is a tool for accessing the Hardware Clock. You can display the current time, set the Hardware Clock to a specified time, set the Hardware Clock from the System Time, or set the System Time from the Hardware Clock
Show differences between hardware clock and system clock:
hwclock --show
Example output:
Mon 11 Feb 2019 11:52:16 AM PST -0.375700 seconds
To set the hardware clock to local time:
hwclock --set --date="2019-03-11 15:12:34" --localtime
Linux Change Timezone
To set or change timezone system clock of your system you need change localtime. For example set local time to Los Angeles:
# cp /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
Linux NTP Sync, Public NTP Server
For synchronize Linux time over network with time servers install ntpdate utility:
for CentOS:
# yum install ntpdate
for Debian systems:
# apt-get update # apt-get install ntpdate
Update time over Internet with public NTP server 0.pool.ntp.org. In your case you can use other public NTP servers:
# ntpdate 0.pool.ntp.org
Example output:
11 Feb 12:20:23 ntpdate[11536]: adjust time server 81.7.16.52 offset 0.000574 sec
2 Comments