Sometimes you may just need to get the date and time quickly set before going on and installing NTP or OpenNTP and configuring them with a NTP server. The following examples show how quickly you can set the date and time at the command shell in Linux.
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 under Linux operating systems?
Type the date command:
$ date
Sample outputs:
Wed Apr 23 10:32:59 CDT [email protected]
Linux Set Date Command Example – 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"
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 Examples:
To set the time to 15:47:
date +%T -s "15:47:00"
To set the date and time to July 10 at 15:50:
date 07101550
To set the time and date including the year to July 10 2012 at 16:00 and 30 seconds:
date -s "10 JUL 2012 16:00:30"
For more info see the man pages in your distro with “man date” command.