Linux Date – How to Set Date Through Command Line

clockdatelinux

How to change the system date in Linux ?

I want to change:

  • Only Year
  • Only Month
  • Only Date
  • Any combination of above three

Best Answer

Use date -s:

date -s '2014-12-25 12:34:56'

Run that as root or under sudo. Changing only one of the year/month/day is more of a challenge and will involve repeating bits of the current date. There are also GUI date tools built in to the major desktop environments, usually accessed through the clock.

To change only part of the time, you can use command substitution in the date string:

date -s "2014-12-25 $(date +%H:%M:%S)"

will change the date, but keep the time. See man date for formatting details to construct other combinations: the individual components are %Y, %m, %d, %H, %M, and %S.

Related Question