Categories: How-To

Localtime file on Linux (defines the timezone) [Basic Guide]

The localtime file on Linux is used to define the time zone zone and thereby change the system clock to local time.

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

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

Or more simply, use the “-sf” option of the ln command, which deletes the previous symbolic link when creating the new one:

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

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

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

/etc/timezone

In Debian-based distributions (Debian, Linux Mint, Ubuntu, etc.), the time zone configuration is controlled through the /etc/timezone file, which contains the Information about which Timezone is. See the example:

$ cat /etc/timezone America/Los_Angeles

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

# echo “America/Sao_Paulo” > /etc/timezone

After changing the content 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 define the logged-in user’s time zone and works for any Linux.

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

This variable is useful for configuring Time Zone information per user. The system can have a time zone, and each connected user can have their own zone when logged in. This can be useful in a server environment with users spread over several zone zones.

See the example:

$ TZ='America/Miami'; export TZ
$ date Sat, Oct 19, 2019 2:37:07 PM America

$ TZ='America/Sao_Paulo'; export TZ
$ date Sat, Oct 19, 2019 11:38:01 AM -03

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

In addition, for the timezone configuration using the TZ variable to be permanent, it must be configured in a user initialization file, preferably in the ~/.profile file.

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

Did you like it?

Share

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Share
Published by
Uirá Endy Ribeiro

Recent Posts

Sudo command on Linux (privilege scale) [Basic Guide]

The sudo command on Linux executes a given command as if it were another user.…

2 years ago

SS command on Linux (investigate the network) [Basic Guide]

The ss command on Linux is extremely useful for investigating sockets, providing various information about…

2 years ago

Free Linux command (memory usage) [Basic Guide]

Free Linux command shows the amount of total memory in use and available, as well…

2 years ago

Linux while command (loop – while) [Basic Guide]

The shell has structures for testing conditions and executing certain program sequences several times (loop),…

2 years ago

Linux fstab file (disk mount setup) [Basic Guide]

The /etc/fstab file stores the configuration of which devices should be mounted and what is…

2 years ago

Netcat command on Linux (Swiss network knife) [Basic Guide]

The Netcat Command in Linux or nc is a utility used to do “almost anything”…

2 years ago

This website uses cookies.