If you've moved or are traveling with your Linux laptop, you may be wondering how to change your system's time zone. It's easy to set your Linux computer's time zone from the command line. Here's how to do it.

Viewing Time Zones With tzselect

tzselect continent selection

On Linux systems, time zones are defined by the Time Zone Database, also known as tzdata, managed by the Internet Assigned Numbers Authority.

As time zones can change politically, it's helpful to have them managed in a central database that other systems can use. Tom Scott explains why this is such a good idea:

To view the names of the time zones in the database for your location, you can use the tzselect command. It's a menu-driven program that will narrow down the name of the time zone you want.

You start with the tzselect command at the shell:

        tzselect
    

This will bring up a menu of continents, and you can drill down through to your country's and your local area's time zone, if applicable.

For example, the Pacific Time Zone is represented as "America/Los_Angeles." tzselect will ask to confirm whether this is correct. After that, it will tell you how to make the change permanent using the $TZ environment variable.

Setting Time Zones With the $TZ Environment Variable

TZ environemntal variable on the linux command line

You can simply set the time zone with the $TZ environment variable. For example, to set it to the Pacific Time Zone:

        export TZ="America/Los_Angeles"
    

To make this change permanent, you can put this line in your shell configuration files like .bashrc or .zshrc.

Related: What Are Environment Variables in Linux? Everything You Need to Know

Setting Time Zones With /etc/timezone and /etc/localtime

/etc/localtime symbolic link

If you want to make system-wide changes to the time zone, such as for a desktop system or a laptop that stays in one location, you can use the /etc/timezone and /etc/localtime files. Which file you'll use depends on which system you're running.

Debian and Ubuntu systems use the former. These files are usually set at installation, but you can change them afterward. To find out which files you use on your system, consult your distribution's documentation.

To change the time zone using /etc/timezone, you'd edit it with any text editor and place the time zone name you got earlier in that file. You'll need to use sudo because the root user owns the file.

For example, to edit it with vim:

        sudo vim /etc/timezone
    

With /etc/localtime, you change the time zone by creating a symbolic link to a binary file that has the same name as the time zone in the /usr/share/zoneinfo directory.

If you wanted to set your machine to Pacific time using /etc/localtime, you'd use the ln command with the -s option to create a symbolic link and -f to overwrite it if it already exists:

        sudo ln -sf /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
    

Now You Can Set the Time Zone From the Command Line

No matter where your travels take you, you can always make sure you're keeping the right time with a few simple commands. If you're looking to convert time zones in the browser, read on for more on how to use a web-based tool, MyTimeZone, to do so.