Sunday, January 3, 2010

Linux Set Date


Q. How can I set the system date and time from the command prompt (bash shell)? I don't have GUI installed and I am login over ssh session. How can I set date?

A. Use date command to display the current date and time or set the system date / time over ssh session.
This is useful if the Linux server time and/or date is wrong, and you need to set it to new values from the shell prompt.

You must login as root user to use date command.


Use the following syntax to set new data and time:
 

date set="STRING"

For example, set new data to 2 Oct 2006 18:00:00, type the following command as root user:
 

# date -s "2 OCT 2006 18:00:00"
 

OR
 

# date set="2 OCT 2006 18:00:00"

You can also simplify format using following syntax:
 

# date +%Y%m%d -s "20081128"

Linux Set Time

To set time use the following syntax:
 

# date +%T -s "10:13:13"
 

Where,
  • 10: Hour (hh)
  • 13: Minute (mm)
  • 30: Second (ss)
Use %p locale’s equivalent of either AM or PM, enter:
 

# date +%T%p -s "6:10:30AM"
# date +%T%p -s "12:10:30PM"


Do check and sync hardware clock with:
 

# hwclock --show
# hwclock --systohc


To get sync time with a remote time server(Do this atleast 3 times, check the offset value to minimum):


# ntpdate -u ip/timeserver


example:


# ntpdate -u 114.130.13.37

OR


# ntpdate -u ntp1.ubuntu.com


THANKS TO VIVEK GITE

No comments:

Post a Comment