Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Linux Tutorials»How to Set or Change the Time Zone in Linux

    How to Set or Change the Time Zone in Linux

    By RahulDecember 24, 20224 Mins Read

    In Linux, the timezone is the system-wide setting that determines the local time on the system. The timezone is stored in the file `/etc/localtime`, which is a symlink to a file in the `/usr/share/zoneinfo` directory that contains the timezone information.

    Advertisement

    It is important to set the correct timezone on your Linux system, as this ensures that the system clock is displaying the correct local time. If the timezone is not set correctly, the system clock may be off for several hours, which can cause issues with scheduling tasks, logs, and other applications.

    In this article, we will walk through the process of setting or changing the timezone in Linux. We will cover two methods: using the `timedatectl` command and directly modifying the `/etc/localtime` file.

    Method 1: Using the `timedatectl` Command

    The `timedatectl` command is a utility that allows you to view and modify the system time and timezone settings. The `timedatectl` command is available on most modern Linux distributions, including CentOS, Fedora, Ubuntu, and Debian.

    To view the current timezone setting, use the following command:

    timedatectl 
    

    The output will look something like this:

    Output
    Local time: Mon 2021-01-18 14:45:34 EST Universal time: Mon 2021-01-18 19:45:34 UTC RTC time: Mon 2021-01-18 19:45:34 Time zone: America/New_York (EST, -0500) System clock synchronized: yes systemd-timesyncd.service active: yes RTC in local TZ: no

    The Time zone line shows the current timezone setting.

    To change the timezone, use the following command:

    ## Syntax 
    timedatectl set-timezone timezone
    

    Replace timezone with the desired timezone. For example, to set the timezone to Asia/Tokyo, use the following command:

    timedatectl set-timezone Asia/Tokyo 
    

    This will update the `/etc/localtime` file and set the timezone to Asia/Tokyo.

    Method 2: Modifying the `/etc/localtime` File

    Another way to set or change the timezone in Linux is to directly modify the `/etc/localtime` file. As mentioned earlier, the `/etc/localtime` file is a symlink to a file in the /usr/share/zoneinfo directory that contains the timezone information. By modifying the `/etc/localtime` file, you can change the timezone setting on the system.

    To view the current timezone setting, use the following command:

    ls -l /etc/localtime 
    

    The output will look something like this:

    Output
    lrwxrwxrwx. 1 root root 36 Jan 18 14:45 /etc/localtime -> /usr/share/zoneinfo/America/New_York

    The `/usr/share/zoneinfo/America/New_York` file is the current timezone setting.

    To change the timezone, you can use the ln command to create a new symlink to a different timezone file in the `/usr/share/zoneinfo` directory. For example, to set the timezone to `Asia/Tokyo`, use the following command:

    ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime 
    

    This will update the `/etc/localtime` file and set the timezone to Asia/Tokyo.

    Note that you will need to have root privileges to modify the `/etc/localtime` file. You can use the sudo command to execute the ln command as the root user.

    I hope this helps you understand how to set or change the timezone in Linux using the `/etc/localtime` file. You can use the `ls -l /usr/share/zoneinfo` command to view a list of available timezone files in the `/usr/share/zoneinfo` directory. Simply replace Asia/Tokyo with the desired timezone file in the ln command to set the timezone to the desired value.

    Conclusion

    In conclusion, setting or changing the timezone in Linux is an important task that ensures the system clock is displaying the correct local time. There are two methods for setting or changing the timezone in Linux: using the `timedatectl` command and directly modifying the `/etc/localtime` file.

    The `timedatectl` command is a utility that allows you to view and modify the system time and timezone settings. To change the timezone using `timedatectl`, use the set-timezone option followed by the desired timezone.

    Alternatively, you can change the timezone by modifying the `/etc/localtime` file, which is a symlink to a file in the `/usr/share/zoneinfo` directory that contains the timezone information. To change the timezone using this method, use the ln command to create a new symlink to the desired timezone file in the `/usr/share/zoneinfo` directory.

    By following these steps, you can set or change the timezone in Linux and ensure that the system clock is displaying the correct local time.

    timedatectl timezone
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    An Introduction to the “./configure” Command: Compiling Source Code in Linux

    Getting Started with Linux Command line: The Beginning

    Backing Up Your Linux System with Rsync: A Step-by-Step Guide

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • tail Command in Linux with Examples
    • What is a Orphan Process in Unix/Linux
    • How To Display Warning Message to Unauthorized SSH Access
    • How to Set a Custom SSH Login Banner and MOTD
    • Understanding Reverse DNS: What it is and Why it Matters?
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.