I'd like to reset the timezone through editing /etc/timezone. However, after I was done editing and saved the file, the system time did not change accordingly.

On the other hand, when I take advantage of the command dpkg-reconfigure tzdata to change the timezone, the time will change immediately. Plus, the /etc/timezone file is modified accordingly.

What steps am I missing after editing and saving the config file in order for the new time to take effect?


5 Answers 5


Since you've found that dpkg-reconfigure tzdata works, why don't you use it?

If the problem is that it's interactive and you want to script the change, it's possible. The timezone is configured through debconf. You can set values with debconf-set-selections. Then reconfigure the package, telling it not to prompt for anything.

debconf-set-selections <<EOF
tzdata tzdata/Areas select Europe
tzdata tzdata/Areas seen true
tzdata tzdata/Zones/Europe select Paris
tzdata tzdata/Zones/Europe seen true
dpkg-reconfigure -fnoninteractive tzdata

Applications read /etc/localtime when they first need the time zone information. This is performed by the system's standard library, so you won't find many exceptions if at all. /etc/localtime is usually a symbolic link to a file under /usr/share/zoneinfo, or a copy of such a file. Most applications need to be restarted for a change of this file to take effect.

The file /etc/timezone contains the name of a time zone. Normally /etc/localtime is a link to or copy of /usr/share/zoneinfo/$(cat /etc/timezone). /etc/timezone is used by the packaging system mainly (only?), which explains why changing it didn't have any visible effect.

Remember that you can use a different timezone in a particular application by starting it with the TZ environment variable, e.g. TZ=Pacific/Tarawa date.


Take a look at /var/lib/dpkg/info/tzdata.postinst, which I think is what is being run when dpkg-reconfigure tzdata is called.

Note in particular the following command, which runs after /etc/timezone has been updated.

cp -f /usr/share/zoneinfo/$AREA/$ZONE /etc/localtime.dpkg-new && \
            mv -f /etc/localtime.dpkg-new /etc/localtime

So, the file /etc/localtime needs to be updated. I haven't tried it, but my guess is that is an important step in making the timezone change. It is unclear if the tzdata maintainer expects you to make this change manually if you have edited /etc/timezone yourself.


You might be able to run service timezone restart to make this take effect manually. This does for just about any system config file. Whatever service depends on those configs will need to be restarted after a file is changed.

Changing the file /etc/timezone is actually be sufficient, but you would normally need to reboot or at least login again for it to take affect. Changing the time zone isn't something system makers anticipated happening enough to make it a frequently re-read config file!

In some cases, you will also need to login again because of environment variables that get set when you first login. For example the system language variable is often set on login and changing the config file will not affect users that are already logged in.

  • It does not seem to work even after rebooting.
    – Terry Li
    Commented Jul 6, 2011 at 20:26
  • And running service timezone restart gave me timezone: unrecognized service error.
    – Terry Li
    Commented Jul 6, 2011 at 20:29

So, something like:

set $area="America"
set $zone="Los_Angeles"
sudo echo "$area/$zone" > /tmp/timezone
sudo cp -f /tmp/timezone /etc/timezone
sudo cp -f /usr/share/zoneinfo/$area/$zone /etc/localtime

I use the following script to ask the user which timezone to set, and then confirm it has indeed been set:

sudo timedatectl set-timezone $(tzselect)
echo timedatectl says:

I call it tz-set.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .