In this article, we’ll show you how to set the timezone from the Ubuntu command line.
Get the current time and timezone settings:
$ sudo timedatectl
In this example, the following time zone is configured on the computer:
Time zone: America/Chicago (CST, -0600)
In most Linux distributions, the time zone is set using a symbolic link from the /etc/localtime
file to a time zone file in the /usr/share/zoneinfo
directory.
You can list all available timezones:
$ sudo timedatectl list-timezones
You can find the timezone you need with grep
$ sudo timedatectl list-timezones | grep Europe
To change the time zone, run the command:
$ sudo timedatectl set-timezone Europe/Berlin
This command also changes the current time zone in the /etc/timezone file.
$ cat /etc/timezone
Make sure that the new time zone is now set on Ubuntu:
$ sudo timedatectl
Or:
$ ls -l /etc/localtime
The command output shows that /etc/localtime points to /usr/share/zoneinfo/Europe/Berlin.
You can also use the pseudo-GUI tzdata or tzselect commands in the Linux console to change the time zone:
$ sudo dpkg-reconfigure tzdata
$ sudo /etc/init.d/cron stop
$ sudo /etc/init.d/cron start