리눅스에서 시간을 설정하는 것은 timedatectl 명령어를 사용한다.
timedatectl 명령어를 옵션 없이 사용하면, 로컬 시간과 유니버설 시간, RTC 시간, 타임존 등 시간 설정값을 확인할 수 있다.
$ timedatectl
Local time: Mon 2024-08-19 00:05:05 UTC
Universal time: Mon 2024-08-19 00:05:05 UTC
RTC time: Mon 2024-08-19 00:05:05
Time zone: UTC (UTC, +0000)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
위의 timedatectl 결과에서 타임존은 UTC로 되어 있기 때문에 한국시간(+0900)과는 맞지 않는다.
한국 시간을 설정하기 위해 타임존을 적용하는 명령어는 set-timezone 옵션을 사용하면 된다.
sudo timedatectl set-timezone Asia/Seoul
OS의 시간을 설정하는 것이기 때문에, 조회할 때와 다르게 sudo를 이용하거나 root 계정을 사용해야 한다.
타임존 설정 명령어를 실행하면 출력되는 결과는 아무것도 없기 때문에, date 명령어를 이용하여 확인해 본다.
date
Mon Aug 19 09:05:36 KST 2024
시간이 현재 한국 시간(작성시간 기준)으로 변경되어 있는 것을 확인할 수 있다.
timedatectl 명령어는 systemd를 사용하는 대부분의 리눅스에서 사용할 수 있으며, 다른 init 시스템을 사용하는 리눅스에서는 date 등 다른 명령어를 사용해야 한다.
아래는 timedatectl의 옵션 설명이다. timedatectl로 조회했을 때 나오는 항목(시간, NTC, RTC, 타임존 등)들에 대해서 각각 설정할 수 있다.
$ timedatectl -h
timedatectl [OPTIONS...] COMMAND ...
Query or change system time and date settings.
-h --help Show this help message
--version Show package version
--no-pager Do not pipe output into a pager
--no-ask-password Do not prompt for password
-H --host=[USER@]HOST Operate on remote host
-M --machine=CONTAINER Operate on local container
--adjust-system-clock Adjust system clock when changing local RTC mode
--monitor Monitor status of systemd-timesyncd
-p --property=NAME Show only properties by this name
-a --all Show all properties, including empty ones
--value When showing properties, only print the value
Commands:
status Show current time settings
show Show properties of systemd-timedated
set-time TIME Set system time
set-timezone ZONE Set system time zone
list-timezones Show known time zones
set-local-rtc BOOL Control whether RTC is in local time
set-ntp BOOL Enable or disable network time synchronization
systemd-timesyncd Commands:
timesync-status Show status of systemd-timesyncd
show-timesync Show properties of systemd-timesyncd
'IT > 리눅스' 카테고리의 다른 글
kubernetes에서 PVC 삭제(그리고 생성)가 안될 때 (0) | 2024.09.13 |
---|---|
kubernetes를 외부에서 접근하는 방법 (0) | 2024.09.12 |
리눅스 명령어 man 검색 시 나타나는 괄호의 숫자 의미 (0) | 2024.08.13 |
yum groupinstall (dnf group install) 이란? (0) | 2024.08.08 |
셸 스크립트를 바이너리 실행파일로 만들기 (0) | 2024.08.07 |