[Linux] Date 날짜 설정 및 데이트 관련 명령어
- 운영체제 / 리눅스
- 2022. 9. 20.
리눅스 Date 명령어 (출력하기)
리눅스에서 Date 명령을 잘 활용하면 다양한 아이디어를 얻을 수 있습니다. 지금 무슨 분기 인지? 몇 주째 되는지 등등 고려해서 스크립트 등을 만들 수 있습니다. 그럼 간단한 사용법을 알아보겠습니다.

▼ 기본적으로 현재 날짜를 출력하는 방법입니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ date | |
Tue Sep 20 12:12:22 PM KST 2022 |
▼ 다음은 년도만 출력합니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ date '+%Y' | |
2022 |
▼ 연도의 뒷자리 2글자만 표현하려면 소문자 y를 사용합니다. 명령 대부분이 대문자, 소문자에 따라 달라집니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ date '+%y%m%d' | |
220920 |
▼ 시간만 나타내려면 다음과 같이 T 문자를 사용합니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ date '+%T' | |
12:14:40 |
▼ 그 밖에 다양한 옵션들입니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% a literal % | |
%a locale's abbreviated weekday name (e.g., Sun) | |
%A locale's full weekday name (e.g., Sunday) | |
%b locale's abbreviated month name (e.g., Jan) | |
%B locale's full month name (e.g., January) | |
%c locale's date and time (e.g., Thu Mar 3 23:05:25 2005) | |
%C century; like %Y, except omit last two digits (e.g., 20) | |
%d day of month (e.g., 01) | |
%D date; same as %m/%d/%y | |
%e day of month, space padded; same as %_d | |
%F full date; like %+4Y-%m-%d | |
%g last two digits of year of ISO week number (see %G) | |
%G year of ISO week number (see %V); normally useful only with %V | |
%h same as %b | |
%H hour (00..23) | |
%I hour (01..12) | |
%j day of year (001..366) | |
%k hour, space padded ( 0..23); same as %_H | |
%l hour, space padded ( 1..12); same as %_I | |
%m month (01..12) | |
%M minute (00..59) | |
%n a newline | |
%N nanoseconds (000000000..999999999) | |
%p locale's equivalent of either AM or PM; blank if not known | |
%P like %p, but lower case | |
%q quarter of year (1..4) | |
%r locale's 12-hour clock time (e.g., 11:11:04 PM) | |
%R 24-hour hour and minute; same as %H:%M | |
%s seconds since 1970-01-01 00:00:00 UTC | |
%S second (00..60) | |
%t a tab | |
%T time; same as %H:%M:%S | |
%u day of week (1..7); 1 is Monday | |
%U week number of year, with Sunday as first day of week (00..53) | |
%V ISO week number, with Monday as first day of week (01..53) | |
%w day of week (0..6); 0 is Sunday | |
%W week number of year, with Monday as first day of week (00..53) | |
%x locale's date representation (e.g., 12/31/99) | |
%X locale's time representation (e.g., 23:13:48) | |
%y last two digits of year (00..99) | |
%Y year | |
%z +hhmm numeric time zone (e.g., -0400) | |
%:z +hh:mm numeric time zone (e.g., -04:00) | |
%::z +hh:mm:ss numeric time zone (e.g., -04:00:00) | |
%:::z numeric time zone with : to necessary precision (e.g., -04, +05:30) | |
%Z alphabetic time zone abbreviation (e.g., EDT) |
▼ 위의 명령어중 예를 들어 현재 타임존을 알고 싶다면 다음과 같이 Z를 입력합니다. 그리고 ' ' 구문 안에 여러 리터럴들을 추가할 수 있습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ date '+%Z' | |
KST |
리눅스 Date 명령어 (수정하기)
▼ 이제 날짜을 수정해보겠습니다. 다음과 같이 날짜를 수정합니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ date -s "2022-07-07" |
▼ 이제 전체 날짜와 시간을 수정해보겠습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ date +%D -s "2022-07-07 14:07:07" |
▼ 마지막으로 시간만 수정해보겠습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ date +%T -s "07:07:00" |
'운영체제 > 리눅스' 카테고리의 다른 글
[Linux] 리눅스 디스크 사용량 확인 df, du 명령어 (0) | 2025.01.16 |
---|---|
[Linux] 리눅스에서 CPU 스트레스 테스트 stress-ng 사용법 (0) | 2025.01.11 |
[Linux] 스트림 (Stream) / 파일 디스크립터 (File Descriptor) (0) | 2024.03.12 |
[Linux] chown, chmod로 하위 폴더 및 파일 권한 변경 (0) | 2023.04.29 |
[Linux] ps: command not found 에러 procps 설치하기 (0) | 2022.09.10 |