How to Set or Change the Time Zone in Linux - Linux Tips And Tricks

Rabi Gurung
Rabi Gurung
954 بار بازدید - پارسال - Discover how to set or
Discover how to set or change the Time Zone in Linux (using BASH Command).

Changing Linux system time and date is relatively easy, but changing time zone is a bit hairy. Let me explain...

Altering the timezone in Linux is a straightforward process that involves a few simple commands. Initially, you must use the 'timedatectl' command in the terminal to determine the current timezone. Subsequently, you can modify the timezone by utilizing the 'timedatectl set-timezone' command, followed by the desired timezone. To illustrate, to modify the timezone to 'America/Los_Angeles,' you would input 'timedatectl set-timezone America/Los_Angeles' into the terminal. However, it is essential to note that knowledge of the timezone name is necessary to modify it. Nevertheless, some may prefer working with numbers. If that is the case, the following video demonstrates how to change the time zone using the hour offset.

Commands featured in this video

Get System Date abd Time Detail
timedatectl

Chaneg System Time Zone Using Area Name
sudo timedatectl set-timezone Europe/Moscow

List Of All Time Zone With -0700
for tz in `cat /usr/share/zoneinfo/zone.tab | awk '{print $3}'`; do TZ=$tz date +"$tz %Z %::z"; done | grep -- -07:00

First Time Zone In List With -0700
for tz in `cat /usr/share/zoneinfo/zone.tab | awk '{print $3}'`; do TZ=$tz date +"$tz %Z %::z"; done | grep -- -07:00 | head -1 | cut -f1 -d ' '

Change Time Zone Using Hour Offset (-0700)
tzone=$(for tz in `cat /usr/share/zoneinfo/zone.tab | awk '{print $3}'`; do TZ=$tz date +"$tz %Z %::z"; done | grep -- -07:00 | head -1 | cut -f1 -d ' ');sudo timedatectl set-timezone $tzone

To disable NTP, use this command.
sudo timedatectl set-ntp false

#linux #ubuntu #redhat #bash
پارسال در تاریخ 1401/12/09 منتشر شده است.
954 بـار بازدید شده
... بیشتر