fbpx Linux /etc/localtime File: Configure Timezone | Certificação Linux

Linux localtime File: How to Configure System Timezone

📅 01/01/2019 ⏱ 3 min ✍️ Uira Ribeiro
Linuxcommands
Linux localtime File: How to Configure System Timezone
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

The localtime file in Linux is used to define the timezone, and thus adjust the system clock to local time.

On Red Hat-based systems (Red Hat, CentOS, Fedora, etc), to change a timezone, you must remove the existing /etc/localtime symbolic link and create a new one with the desired timezone zone file:

# rm -f /etc/localtime# ln -s /usr/share/zoneinfo/America/Sao_Paulo /etc/localtime

Or more simply, use the ln command's "-sf" option which removes the previous symbolic link before creating the new one:

# ln -sf /usr/shave/zoneinfo/America/Sao_Paulo /etc/localtime

In this example, the São Paulo timezone will be used by the system.

Once the zone is changed, the clock adjusts automatically to the new time.

/etc/timezone

On Debian-based distributions (Debian, Linux Mint, Ubuntu, etc), the timezone configuration is controlled through the /etc/timezone file, which contains the information about what the timezone is. See the example:

$ cat /etc/timezone America/Los_Angeles

The text to be placed in the /etc/timezone file must match the zone name contained in the /usr/share/zoneinfo/ directory:

# echo "America/Sao_Paulo" > /etc/timezone

After changing the contents of the /etc/timezone file, it is necessary to reconfigure the tzdata package:

# dpkg-reconfigure -f noninteractive tzdata

TZ Variable

The TZ variable can also be used to set the timezone for the logged-in user and works on any Linux.

If this variable is not set, the information from /etc/localtime or /etc/timezone will be used.

This variable is useful for configuring timezone information per user. The system can have one timezone, and each logged-in user can have their own zone. This can be useful in a server environment with users spread across different timezones.

See the example:

$ TZ='America/Miami'; export TZ
$ dateSat 19 Oct 2019 02:37:07 PM America
$ TZ='America/Sao_Paulo'; export TZ
$ dateSat 19 Oct 2019 11:38:01 AM -03

Like any environment variable, for it to work for programs executed in the shell, it must be exported with the "export" command.

Additionally, for the timezone configuration through the TZ variable to be permanent, it must be configured in one of the user's initialization files, preferably in the ~/.profile file.

Learn much more about Linux in our online course. You can enroll here. If you already have an account, or want to create one, just log in or create your user here.

Liked it? Share

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp