Set date and time in Linux

There are many times that you need to set date and time in Linux, here are the commands you can use.

To set date only in linux:

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

To set both date and time at the same time:

date -s "2 OCT 2016 18:00:00"

You need to follow the format of date/time string. If you want more formats, you can take a look the man page of date command.

man date

You can also use ntp command to sync time from time server, here is an example:

ntpdate 1.ro.pool.ntp.org

You might need to install ntpdate first by using one of the commands:

sudo apt-get install ntpdate
yum install ntp

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *