At some point whilst working with linux systems, it is quite likely that you will have to change or configure the date, time and locale information. When using a GUI based system this is very simple, you simply browse through the system settings (which vary by distribution) and change it with your mouse and keyboard. However, when administering headless (command line only) systems, it is a bit more complicated and in fact, there’s a few ways to do it. You can view the current information by issuing the date command.

Changing the Timezone with zoneinfo files

Traditionally the command tzconfig was used to change the time and date information (timezone), but this command has now been deprecated and thus, we must do it a different way.

There are a number of timezone files located in /usr/share/zoneinfo, note down the name of the appropriate file.

zone

The current active values for the timezone are stored in the file /etc/localtime. In order to change the time we must edit this file and replace its content with that of the appropriate file form the /usr/share/zoneinfo folder. Now, you could copy the contents from the zoneinfo file to the localtime file but there’s a few drawbacks to doing that. Primarily, an issue arises if the time zone changes at some point in the year due to daylight saving: the source zoneinfo file will often be automatically adjusted by the operating system and will know about daylight saving. If you have simply copied a “static” version of the contents to the localtime file this will not be updated. Therefore, it’s probably a better idea to create a symbolic link, like i have below. This ensures a dynamic relationship between the source and destination file and means that the localtime file will remain a “clone” of the source file. Therefore any changes in the source will update the destination.

locale-link

In some distributions there are easier ways to change the timezone info, but it’s useful to know how to do it manually in case you find yourself needing to do it. In debain based distributions (distros) for example, we can often use dpkg to reconfigure the timezone, which automates much of the above process, by running dpkg-reconfigure tzdata . We are then presented with an interactive menu, allowing us to configured the desired values.

locale-gui

Changing locale environment variables

If you wish to change things such as the system language, character set or date and time format; you can do it by changing some of your locale environmental variables. To view your current locale variable values, issue locale. You can then change some or all of the values using export. Below I change the LANG variable to GB UTF-8 instead of US.

locale-export