카테고리 없음

리눅스 TimeZone 변경

필유아사 2022. 6. 24. 15:05

How to Set or Change the Time Zone in Linux

 

현재 TimeZone 확인

timedatectl은 시스템의 시간과 날짜를 보고 변경할 수 있는 명령어입니다. 모든 최신 시스템 기반 Linux 시스템에서 사용할 수 있습니다.

현재 시간대를 보려면 옵션이나 인수 없이 timedatectl 명령을 실행합니다.

 

timedatectl
               Local time: Fri 2022-06-24 05:50:38 UTC
           Universal time: Fri 2022-06-24 05:50:38 UTC
                 RTC time: Fri 2022-06-24 05:50:38
                Time zone: Etc/UTC (UTC, +0000)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

 

위의 출력은 시스템의 시간대가 UTC로 설정되었음을 보여줍니다.
시스템 시간대는 /etc/localtime 파일을 /usr/share/zoneinfo 디렉토리의 바이너리 timezone 에 심볼릭 링크로 구성됩니다.

 

시간대를 확인하는 또 다른 방법은 ls 명령을 사용하여 심볼릭 링크가 가리키는 경로를 보는 것입니다.

ls -l /etc/localtime
lrwxrwxrwx 1 root root 27 Dec  3 16:29 /etc/localtime -> /usr/share/zoneinfo/Etc/UTC

Time Zone 변경

시간대를 변경하기 전에 사용하려는 시간대 이름을 찾아야 합니다. 표준 시간대 명명 규칙은 일반적으로 "지역/도시" 형식을 사용합니다.
사용 가능한 모든 시간대를 보려면 timedatectl 명령을 사용하거나 /usr/share/zoneinfo 디렉토리에 있는 파일을 나열합니다.

timedatectl list-timezones

...
America/Montserrat
America/Nassau
America/New_York
America/Nipigon
America/Nome
America/Noronha
...

현재 위치에 맞는 시간대를 확인한 후 루트 또는 sudo 로 다음 명령을 실행합니다.

sudo timedatectl set-timezone <your_time_zone>

예를 들어 시스템의 시간대를 Asia/Seoul 로 변경하려면 다음을 입력합니다.

sudo timedatectl set-timezone Asia/Seoul

변경 사항을 확인하려면 timedatectl 명령을 다시 호출합니다.

timedatectl

               Local time: Fri 2022-06-24 15:00:17 KST
           Universal time: Fri 2022-06-24 06:00:17 UTC
                 RTC time: Fri 2022-06-24 06:00:17
                Time zone: Asia/Seoul (KST, +0900)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

 

이전 Linux 배포판을 실행 중이고 시스템에 timedatectl 유틸리티가 없는 경우 /etc/localtime을 /usr/share/zoneinfo 디렉토리의 시간대에 심볼릭 링크하여 시간대를 변경할 수 있습니다.
현재 심볼릭 링크 또는 파일을 제거합니다.

sudo rm -rf /etc/localtime

구성하려는 시간대를 식별하고 symlink를 생성합니다.

sudo ln -s /usr/share/zoneinfo/Asia/Seoul /etc/localtime

 

/etc/localtime 파일을 나열하거나 date 명령어로 변경된 시간을 확인합니다.

date