Change your Time Zone to EST in Ubuntu

NOTE: This was tested on Ubuntu 20.04 LTS

I live in a Eastern Standard Time Zone and I want to change my server to reflect this! How? See below for the Tada! πŸ˜€

Below I crafted a handy Perl one liner to the rescue!

sudo perl -i"_$(date +%s).bak" -0777 -pse '$_ = $tz; END { system "$save && date" }' -- -tz='America/Toronto' -save='sudo dpkg-reconfigure --frontend noninteractive tzdata' /etc/timezone

Perl Parameter Breakdown:

  • -i”_$(date +%s).bak” = Inline edit mode. The added syntax makes a backup of the file with an epoch timestamp.
  • -0777 = This is equivalent to a file slurp, it loads all the contents into memory at once.
  • -p = loop & print, this creates a while continue loop that auto prints the $_ variable, used in conjunction with -i it forces it to write to the file instead of STDOUT.
  • -s = switch mode lets you create variables after the -- construct. For example -go=”contents” creates a $go variable.
  • -e = Execute the code wrapped in the single quote delimiter.

Time Zone Related Items

  • /etc/timezone = location of the time zone info
  • sudo dpkg-reconfigure –frontend noninteractive tzdata = the command that initializes the new configuration

πŸ‘ Get Blog Updates

πŸ“ Latest Posts


Leave a Reply