date 명령어 (AIX 5.3·6.1)
https://archive.horanglab.com/posts/aix-cmd-date
핵심 정리
- 플래그 없이(또는
+로 시작하는 형식과 함께) 실행하면 현재 날짜와 시각을 출력하고, 날짜 인수를 주면 시스템 날짜를 바꿉니다(root만). - 설정 형식:
mmddHHMM[YYyy]또는mmddHHMM[yy](예:date 0217142590은 1990년 2월 17일 14:25). - 출력 형식:
date +"%Y-%m-%d %H:%M:%S"처럼+뒤에%지정자를 씁니다.%s는 1970년 1월 1일부터의 초입니다. -u는 협정 세계시(CUT/UTC)로 보이거나 설정하고,-a [+|-]sss.fff는 시계를 그 초만큼 서서히 맞춥니다.- 두 자리 연도 7099는 19701999, 0037은 20002037입니다. 6.1은 2038~2105년을 네 자리로 받습니다(5.3은 2037년까지).
- 여러 사용자가 쓰는 동안에는 날짜를 바꾸지 않습니다.
| 항목 | 내용 |
|---|---|
| 버전 | AIX 5.3, AIX 6.1 (6.1에서 2038~2105년을 쓸 수 있게 되고 보안 절이 더해짐) |
| 원문 | IBM Commands Reference — 5.3 Volume 2, 6.1 Volume 2 |
| 파일 | /usr/bin/date |
| 관련 명령어 | setclock, xntpd, time |
목적
날짜와 시각을 표시하거나 설정합니다.
영어 원문
Displays or sets the date or time.
구문
root 사용자가 날짜와 시각을 설정할 때:
/usr/bin/date [ -n ] [ -u ] [ Date ] [ +FieldDescriptor ... ]
날짜와 시각을 표시할 때:
/usr/bin/date [ -u ] [ +FieldDescriptor ... ]
root 사용자가 시각을 초 단위로 조정할 때:
/usr/bin/date [ -a [ + | - ] sss[.fff] ]
설명
주의: 여러 사용자가 시스템을 쓰고 있을 때는 날짜를 바꾸지 마세요.
date 명령은 플래그 없이, 또는 +(더하기)로 시작하는 플래그 목록과 함께 부르면 현재 날짜와 시각을 표준 출력에 씁니다. 그렇지 않으면 현재 날짜를 설정합니다. 날짜와 시각은 root 사용자만 바꿀 수 있습니다. 알 수 없는 플래그나 입력이 있으면 사용법 메시지를 출력합니다.
Date 매개변수로 날짜를 설정할 때는 다음 형식을 씁니다.
mmddHHMM[YYyy]
mmddHHMM[yy]
| 자리 | 뜻 |
|---|---|
mm |
월 |
dd |
일 |
HH |
시(24시간제) |
MM |
분 |
YY |
연도의 앞 두 자리. 지정하지 않으면 7099는 20세기(19701999), 0037은 21세기(20002037)로 봅니다. |
yy |
연도의 뒤 두 자리. 네 자리 연도도 받으며, 범위를 벗어나면(1970 미만, 2105 초과) 실패합니다. 2038~2105년은 네 자리로 지정합니다(6.1. 5.3은 2037년까지). |
연도를 지정하지 않으면 올해가 기본입니다. 시스템은 협정 세계시(CUT)로 동작합니다.
date 뒤에 +와 필드 기술자를 주면 출력 형태를 정할 수 있습니다. 필드 기술자마다 앞에 %를 붙이며, 시스템이 그것을 해당 값으로 바꿉니다. % 글자 자체는 %%로 씁니다. 다른 문자는 그대로 출력하며, 끝에는 늘 줄바꿈을 붙입니다.
영어 원문
Attention: Do not change the date when the system is running with more than one user.
The date command writes the current date and time to standard output if called with no flags or with a flag list that begins with a + (plus sign). Otherwise, it sets the current date. Only a root user can change the date and time. The date command prints the usage message on any unrecognized flags or input.
The following formats can be used when you set the date with the Date parameter:
mmddHHMM[YYyy]
mmddHHMM[yy]
The variables to the Date parameter are defined as follows:
- mm — Specifies the month number.
- dd — Specifies the number of the day in the month.
- HH — Specifies the hour in the day by using a 24-hour clock.
- MM — Specifies the minute number.
- YY — Specifies the first 2 digits of the year. Note: If you do not specify the first 2 digits of the year, values in the range 70 - 99 refer to the 20th century, 1970 - 1999 inclusive. Similarly, values in the range 00 - 37 refer to years in the 21st century, 2000 - 2037 inclusive.
- yy — Specifies the last 2 digits of the year. Note: The date command accepts a 4-digit year as input. For example, if a 4-digit year is specified, the date command tries to set the year to YYyy and fails for values that are out of range (less than 1970 and greater than 2105). For years in the range 2038 - 2105, specify the year in the yyyy format.
The current year is used as the default value when the year is not specified. The system operates in Coordinated Universal Time (CUT).
If you follow the date command with a + (plus sign) and a field descriptor, you can control the output of the command. You must precede each field descriptor with a % (percent sign). The system replaces the field descriptor with the specified value. Enter a literal % as %% (two percent signs). The date command copies any other characters to the output without change. The date command always ends the string with a new-line character.
플래그
| 플래그 | 설명 |
|---|---|
-a [+ | -]sss[.fff] |
시각을 sss.fff초(fff는 소수 부분)만큼 서서히 조정합니다. 양수나 음수를 쓸 수 있으며, 지정한 초만큼 어긋날 때까지 시스템 시계를 빠르게 하거나 느리게 합니다. |
-n |
시계를 동기화하는 로컬 네트워크의 모든 시스템에 시각을 전역으로 설정하지 않습니다. |
-u |
협정 세계시(CUT)로 시각을 표시하거나 설정합니다. |
필드 기술자
| 기술자 | 표시하는 것 |
|---|---|
%a |
로캘의 요일 줄임 이름 |
%A |
로캘의 요일 전체 이름 |
%b |
로캘의 월 줄임 이름 |
%B |
로캘의 월 전체 이름 |
%c |
로캘에 맞는 날짜·시각 표현(기본) |
%C |
네 자리 연도의 앞 두 자리(00~99). 연도를 100으로 나눠 정수로 자른 값 |
%d |
일(01~31). 두 자리에서 앞을 0으로 채움 |
%D |
%m/%d/%y와 같은 형식의 날짜 |
%e |
일(1~31). 두 자리에서 앞을 빈칸으로 채움 |
%h |
로캘의 월 줄임 이름(%b와 같음) |
%H |
시(24시간제, 00~23) |
%I |
시(12시간제, 01~12) |
%j |
연중 날짜(001~366) |
%k |
시(24시간제, 0~23). 오른쪽 맞춤, 빈칸 채움 |
%m |
월(01~12) |
%M |
분(00~59) |
%n |
줄바꿈 |
%p |
로캘의 AM 또는 PM |
%r |
AM·PM 표기의 12시간제 시각. POSIX 로캘에서는 %I:%M:%S %p와 같음 |
%S |
초(00~59) |
%s |
1970년 1월 1일 협정 세계시부터 지난 초 |
%t |
탭 |
%T |
HH:MM:SS 형식의 24시간제 시각 |
%u |
요일(1~7, 일요일 = 7) |
%U |
연중 주 번호(일요일 시작, 00~53). 첫 일요일 전의 날은 0주 |
%V |
연중 주 번호(월요일 시작, 01~53). 1월 1일이 든 주에 새해 날이 4일 이상이면 1주, 아니면 지난해 53주 |
%w |
요일(0~6, 일요일 = 0) |
%W |
연중 주 번호(월요일 시작, 00~53) |
%x |
로캘에 맞는 날짜 표현 |
%X |
로캘에 맞는 시각 표현 |
%y |
연도의 뒤 두 자리(00~99) |
%Y |
네 자리 연도 |
%Z |
시간대 이름(알 수 없으면 없음) |
%% |
% 문자 |
수정된 필드 기술자
%E와 %O는 Files Reference의 "LC_TIME Category for the Locale Definition Source File Format"에서 설명하는 다른 형식을 나타냅니다. 현재 로캘에 해당 키워드(era, era_year, era_d_fmt, alt_digits)가 없거나 지원하지 않으면 수정하지 않은 기술자의 값을 씁니다.
| 기술자 | 표시하는 것 |
|---|---|
%Ec |
로캘의 다른 날짜·시각 표현 |
%EC |
기준 연도(또는 기간)의 이름(다른 표현) |
%Ex |
로캘의 다른 날짜 표현 |
%EX |
로캘의 다른 시각 표현 |
%Ey |
%EC로부터의 연도 차(다른 표현) |
%EY |
다른 표현의 전체 연도 |
%Od, %Oe |
로캘의 다른 숫자 기호로 쓴 일 |
%OH |
다른 숫자 기호로 쓴 시(24시간제) |
%OI |
다른 숫자 기호로 쓴 시(12시간제) |
%Om |
다른 숫자 기호로 쓴 월 |
%OM |
다른 숫자 기호로 쓴 분 |
%OS |
다른 숫자 기호로 쓴 초 |
%Ou |
다른 표현의 요일 번호(월요일 = 1) |
%OU |
다른 숫자 기호로 쓴 주 번호(일요일 시작) |
%OV |
다른 숫자 기호로 쓴 주 번호(월요일 시작) |
%Ow |
다른 표현의 요일 번호(일요일 = 0) |
%OW |
다른 숫자 기호로 쓴 주 번호(월요일 시작) |
%Oy |
%C로부터의 연도(다른 표현) |
영어 원문
-a[+|-] sss[.fff] — Slowly adjusts the time by sss.fff seconds (fff represents fractions of a second). This adjustment can be positive or negative. The system's clock is speeded up or slowed down until it is drifted by the number of seconds specified.-n— Does not set the time globally on all systems in a local area network that have their clocks that are synchronized.-u— Displays or sets the time in Coordinated Universal Time (CUT).- Field Descriptors
%a— Displays the locale's abbreviated weekday name.%A— Displays the locale's full weekday name.%b— Displays the locale's abbreviated month name.%B— Displays the locale's full month name.%c— Displays the locale's appropriate date and time representation (default).%C— Displays the first 2 digits of the four-digit year as a decimal number (00-99). A year is divided by 100 and truncated to an integer.%d— Displays the day of the month as a decimal number (01-31). In a two-digit field, a 0 is used as leading space fill.%D— Displays the date in the format equivalent to%m/%d/%y.%e— Displays the day of the month as a decimal number (1-31). In a two-digit field, a blank space is used as leading space fill.%h— Displays the locale's abbreviated month name (a synonym for%b).%H— Displays the hour (24-hour clock) as a decimal number (00-23).%I— Displays the hour (12-hour clock) as a decimal number (01-12).%j— Displays the day of year as a decimal number (001-366).%k— Displays the 24-hour-clock hour clock as a right-align, space-filled number (0 - 23).%m— Displays the month of year as a decimal number (01-12).%M— Displays the minutes as a decimal number (00-59).%n— Inserts a new-line character.%p— Displays the locale's equivalent of either AM or PM.%r— Displays 12-hour clock time (01-12) using the AM-PM notation; in the POSIX locale, it is equivalent to%I:%M:%S %p.%S— Displays the seconds as a decimal number (00 - 59).%s— Displays the number of seconds since January 1, 1970, Coordinated Universal Time (CUT).%t— Inserts a<tab>character.%T— Displays the 24-hour clock (00-23) in the format equivalent toHH:MM:SS.%u— Displays the weekday as a decimal number in the range 1-7 (Sunday = 7). Refer to the%wfield descriptor.%U— Displays week of the year (Sunday as the first day of the week) as a decimal number [00 - 53]. All days in a new year that precede the first Sunday are considered to be in week 0.%V— Displays the week of the year as a decimal number in the range 01-53 (Monday is used as the first day of the week). If the week that contains January 1 has four or more days in the new year, then it is considered week 01. Otherwise, it is week 53 of the previous year.%w— Displays the weekday as a decimal number in the range 0-6 (Sunday = 0). Refer to the%ufield descriptor.%W— Displays the week number of the year as a decimal number (00-53) counting Monday as the first day of the week.%x— Displays the locale's appropriate date representation.%X— Displays the locale's appropriate time representation.%y— Displays the last 2 numbers of the year (00-99).%Y— Displays the four-digit year as a decimal number.%Z— Displays the time-zone name, or no characters if no time zone is determinable.%%— Displays a % (percent sign) character.- Modified Field Descriptors
The %E and %O field descriptors can be modified to indicate a different format or specification, as described in LC_TIME Category for the Locale Definition Source File Format in Files Reference. If the corresponding keyword (see the era, era_year, era_d_fmt, and alt_digits keywords) is not specified or not supported for the current locale, the unmodified field descriptor value is used.
%Ec— Displays the locale's alternative appropriate date and time representation.%EC— Displays the name of the base year (or other time period) in the locale's alternative representation.%Ex— Displays the locale's alternative date representation.%EX— Displays the locale's alternative time representation.%Ey— Displays the offset from the%ECfield descriptor (year only) in the locale's alternative representation.%EY— Displays the full alternative year representation.%Od— Displays the day of the month using the locale's alternative numeric symbols.%Oe— Displays the day of the month using the locale's alternative numeric symbols.%OH— Displays the hour (24-hour clock) using the locale's alternative numeric symbols.%OI— Displays the hour (12-hour clock) using the locale's alternative numeric symbols.%Om— Displays the month using the locale's alternative numeric symbols.%OM— Displays minutes using the locale's alternative numeric symbols.%OS— Displays seconds using the locale's alternative numeric symbols.%Ou— Displays the weekday as a number in the locale's alternative representation (Monday=1).%OU— Displays the week number of the year using the locale's alternative numeric symbols. Sunday is considered the first day of the week.%OV— Displays the week number of the year using the locale's alternative numeric symbols. Monday is considered the first day of the week.%Ow— Displays the weekday as a number in the locale's alternative representation (Sunday =0).%OW— Displays the week number of the year using the locale's alternative numeric symbols. Monday is considered the first day of the week.%Oy— Displays the year (offset from %C) in alternative representation.
종료 상태
| 값 | 뜻 |
|---|---|
| 0 | 날짜를 잘 썼습니다. |
| 0보다 큼 | 오류가 났습니다. |
영어 원문
This command returns the following exit values:
- 0 — The date was written successfully.
>0— An error occurred.
보안
RBAC 사용자와 Trusted AIX 사용자는 주의하세요. 이 명령은 특권 작업을 할 수 있으며, 특권 작업은 특권 사용자만 할 수 있습니다. 특권과 권한 목록은 lssecattr 명령이나 getcmdattr 하위 명령으로 봅니다. 이 절은 6.1 문서에만 있습니다.
영어 원문
Attention RBAC users and Trusted AIX users: This command can perform privileged operations. Only privileged users can run privileged operations. For more information about authorizations and privileges, see Privileged Command Database in Security. For a list of privileges and the authorizations associated with this command, see the lssecattr command or the getcmdattr subcommand.
예제
- 현재 날짜와 시각을 표시합니다.
date
- 날짜와 시각을 설정합니다. 시간대가 CST인 시스템에서 날짜와 시각을 1990년 2월 17일 14:25:00 CST로 정합니다. root 권한이 있어야 합니다.
date 0217142590
- 지정한 형식으로 날짜와 시각을 표시합니다. 예제 2에서 정한 날짜를 다음과 같이 보여 줍니다.
date +"%r %a %d %h %y (Julian Date: %j)"
02:25:03 PM Fri 17 Feb 90 (Julian Date: 048)
영어 원문
- To display current date and time, enter:
date
- To set the date and time, enter:
date 0217142590
For a system that uses CST as its time zone, this command sets the date and time to Sat Feb 17 14:25:00 CST 1990.
Note: You must have root authority to change the date and time.
- To display the date and time in a specified format, enter:
date +"%r %a %d %h %y (Julian Date: %j)"
This command displays the date that is shown in Example 2 as:
02:25:03 PM Fri 17 Feb 90 (Julian Date: 048)
환경 변수
| 변수 | 쓰임 |
|---|---|
LANG |
LC_ALL과 해당 LC_ 변수가 로캘을 정하지 않을 때 쓸 로캘을 정합니다. |
LC_ALL |
LANG이나 LC_로 시작하는 변수가 정한 로캘 범주의 값보다 우선하는 로캘을 정합니다. |
LC_CTYPE |
텍스트 데이터의 바이트를 문자로 해석하는 로캘(단일 바이트, 다중 바이트 등)을 정합니다. |
LC_MESSAGES |
메시지를 쓸 언어를 정합니다. |
LC_TIME |
date가 쓰는 날짜·시각 문자열의 내용을 정합니다. |
NLSPATH |
LC_MESSAGES 처리에 쓸 메시지 카탈로그의 위치를 정합니다. |
TZ |
-u를 지정하지 않으면 날짜와 시각을 쓸 시간대를 정합니다. TZ가 없고 -u도 없으면 시스템 기본 시간대를 씁니다. |
관련 명령어: time, localtime 서브루틴
영어 원문
The following environment variables affect the execution of the date command.
- LANG — Determines the locale to use when both
LC_ALLand the corresponding environment variable (beginning withLC_) do not specify a locale. LC_ALL— Determines the locale to be used to override any values for locale categories that are specified by the setting of LANG or any environment variable beginning withLC_.LC_CTYPE— Determines the locale for the interpretation of sequences of bytes of text data as characters (for example, single versus multibyte character in an argument).LC_MESSAGES— Determines the language in which messages are to be written.LC_TIME— Determines the contents of date and time strings that are written by the date command.- NLSPATH — Determines the location of message catalogs for the processing of
LC_MESSAGES. - TZ — Specifies the time zone in which the time and date are written, unless the
-uflag is specified. If the TZ variable is not set and the-uflag is not specified, an unspecified system default time zone is used.
Related information:
- localtime command
- time command
LC_TIMECategory- Understanding Locale
리눅스(GNU)와 다른 점
| 항목 | AIX 5.3·6.1 | GNU date |
|---|---|---|
| 설정 형식 | mmddHHMM[YYyy] |
MMDDhhmm[[CC]YY][.ss], -s "문자열" |
-a |
시계를 서서히 조정 | 없음(adjtimex, chronyc 등) |
-d "문자열" |
없음 | 임의 날짜 문자열 해석(-d yesterday) |
-n |
네트워크 동기화 시스템에 전역 설정 안 함 | 없음 |
AIX 5.3·6.1 문서에는 -d, -r 파일, -I(ISO 8601), -R 같은 GNU 옵션이 없습니다. 어제 날짜처럼 날짜를 계산하려면 TZ 조정이나 perl을 쓰는 방법이 흔히 쓰입니다.