touch 명령어 (AIX 5.3·6.1)

핵심 정리

  • 파일이나 디렉터리의 접근 시각과 수정 시각을 바꿉니다. 시각을 주지 않으면 현재 시각을 씁니다.
  • 없는 파일을 지정하면 빈 파일을 만듭니다. -c를 주면 만들지 않습니다.
  • -a는 접근 시각만, -m은 수정 시각만 바꿉니다. -r 참조파일은 그 파일의 시각을 씁니다.
  • -t [[CC]YY]MMDDhhmm[.SS]로 시각을 정합니다(예: -t 198503030303.55). 옛 형식 MMDDhhmm[YY]도 받습니다.
  • 두 자리 연도 7099는 1900년대, 0037은 2000년대로 봅니다. 5.3은 2038년 이후 날짜를 받지 않고, 6.1은 네 자리 연도로 쓰면 받습니다.
  • 종료 코드는 시각을 바꾸지 못한 파일의 수입니다.
항목 내용
버전 AIX 5.3, AIX 6.1 (6.1에서 연도 범위 설명이 더해지고, 2038년 이후 날짜를 쓸 수 있게 됨, 보안 절 추가)
원문 IBM Commands Reference — 5.3 Volume 5, 6.1 Volume 5
파일 /usr/bin/touch
관련 명령어 date, make

목적

파일의 접근 시각과 수정 시각을 바꿉니다.

영어 원문

Updates the access and modification times of a file.

구문

text
touch [ -a ] [ -c ] [ -m ] [ -f ] [ -r RefFile ] [ Time | -t Time ] { File ... | Directory ... }

설명

touch 명령은 File 매개변수로 지정한 파일마다, 또는 Directory 매개변수로 지정한 디렉터리마다 접근 시각과 수정 시각을 바꿉니다. Time 변수에 값을 주지 않으면 현재 시각을 씁니다. 없는 파일을 지정하면 -c 플래그를 주지 않는 한 그 파일을 만듭니다.

touch 명령의 반환 코드는 시각을 바꾸지 못한 파일의 수입니다(없어서 만들지 않은 파일 포함).

영어 원문

The touch command updates the access and modification times of each file specified by the File parameter of each directory specified by the Directory parameter. If you do not specify a value for the Time variable, the touch command uses the current time. If you specify a file that does not exist, the touch command creates the file unless you specify the -c flag.

The return code from the touch command is the number of files for which the times could not be successfully modified (including files that did not exist and were not created).

플래그

플래그 설명
-a File의 접근 시각을 바꿉니다. -m도 지정하지 않으면 수정 시각은 바꾸지 않습니다.
-c 파일이 없으면 만들지 않습니다. 이에 대한 진단 메시지도 쓰지 않습니다.
-f 파일의 읽기·쓰기 권한과 상관없이 시각을 바꾸려고 시도합니다.
-m File의 수정 시각을 바꿉니다. -a도 지정하지 않으면 접근 시각은 바꾸지 않습니다.
-r RefFile 현재 시각 대신 RefFile 파일의 해당 시각을 씁니다.
Time 새 시각을 MMDDhhmm[YY] 형식으로 지정합니다(아래 표).
-t Time 현재 시각 대신 지정한 시각을 씁니다. 형식은 10진수 [[CC]YY]MMDDhhmm[.SS]입니다(아래 표).

Time의 각 자리

자리 뜻
CC 연도의 앞 두 자리(19~21). -t에서만 씁니다.
YY 연도의 뒤 두 자리(0099). 생략하면 올해입니다. 7099면 앞자리를 19로, 00~37이면 20으로 봅니다.
MM 월(01~12)
DD 일(01~31)
hh 시(00~23)
mm 분(00~59)
SS 초(00~59). -t에서만 씁니다.
  • 6.1: 2038년 이후는 연도를 네 자리(yyyy)로 지정합니다.
  • 5.3: "2038년부터는 날짜가 유효하지 않다"고 적혀 있고, 위 연도 범위 설명은 없습니다.

참고:

  1. touch는 utime() 서브루틴을 불러 파일의 수정·접근 시각을 바꿉니다. 그래서 파일에 쓰기 권한이 있어도 소유자가 아니면 플래그를 쓸 때 실패할 수 있습니다.
  2. touch를 쓰다가 오류 메시지가 나오면 전체 경로 /usr/bin/touch로 지정하지 마세요.
영어 원문
  • -a — Changes the access time of the file specified by the File variable. Does not change the modification time unless -m is also specified.
  • -c — Does not create the file if it does not already exist. No diagnostic messages are written concerning this condition.
  • -f — Attempts to force the touch in spite of read and write permissions on a file.
  • -m — Changes the modification time of File. Does not change the access time unless -a is also specified.
  • -r RefFile — Uses the corresponding time of the file specified by the RefFile variable instead of the current time.
  • Time — Specifies the date and time of the new timestamp in the format MMDDhhmm[YY], where: MM Specifies the month of the year (01 to 12). DD Specifies the day of the month (01 to 31). hh Specifies the hour of the day (00 to 23). mm Specifies the minute of the hour (00 to 59). YY Specifies the last two digits of the year. If the YY variable is not specified, the default value is the current year (70 to 99 or 00 to 37). If the value of the YY digits is between 70 and 99, the century is assumed to be 19. If the value of the YY digits is between 00 and 37, the century is assumed to be 20.
  • -t Time — Uses the specified time instead of the current time. The Time variable is specified in the decimal form [[CC]YY]MMDDhhmm[.SS] where: CC Specifies the first two digits of the year (19 to 21). YY Specifies the last two digits of the year (00 to 99). If the value of the YY digits is between 70 and 99, the value of the CC digits is assumed to be 19. If the value of the YY digits is between 00 and 37, the value of the CC digits is assumed to be 20. For years after 2038, specify the year in the yyyy format. MM Specifies the month of the year (01 to 12). DD Specifies the day of the month (01 to 31). hh Specifies the hour of the day (00 to 23). mm Specifies the minute of the hour (00 to 59). SS Specifies the second of the minute (00 to 59).
  • Note:
  1. The touch command calls the utime () subroutine to change the modification and access times of the file touched. This may cause the touch command to fail when flags are used if you do not actually own the file, even though you may have write permission to the file.

  2. Do not specify the full path name /usr/bin/touch if you receive an error message when using the touch command.

종료 상태

값 뜻
0 잘 실행했고 요청한 변경을 모두 했습니다.
0보다 큼 오류가 났습니다.
영어 원문

This command returns the following exit values:

  • 0 — The command executed successfully. All requested changes were made.
  • >0 — An error occurred.

보안

RBAC 사용자와 Trusted AIX 사용자는 주의하세요. 이 명령은 특권 작업을 할 수 있으며, 특권 작업은 특권 사용자만 할 수 있습니다. 이 명령에 걸린 특권과 권한(authorization) 목록은 lssecattr 명령이나 getcmdattr 하위 명령으로 봅니다. 이 절은 6.1 문서에만 있습니다.

영어 원문

hm

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.

예제

  1. 파일의 접근 시각과 수정 시각을 바꿉니다. program.c의 마지막 접근·수정 시각을 현재 날짜와 시각으로 정합니다. program.c가 없으면 그 이름의 빈 파일을 만듭니다.
bash
touch program.c
  1. 새 파일을 만들지 않게 합니다.
bash
touch -c program.c
  1. 수정 시각만 바꿉니다. 현재 디렉터리에서 .o로 끝나는 파일의 마지막 수정 시각(접근 시각은 아님)을 바꿉니다. make 명령의 결과를 바꿀 때 흔히 이렇게 씁니다.
bash
touch -m *.o
  1. 접근 시각과 수정 시각을 직접 정합니다. 올해 2월 17일 14시 25분(오후 2시 25분)으로 정합니다.
bash
touch -c -t 02171425 program.c
  1. 현재 시각 대신 다른 파일의 시각을 씁니다. program.c에 file1과 같은 시각을 줍니다.
bash
touch -r file1 program.c
  1. 현재 시각이 아닌 지정한 시각으로 바꿉니다. program.c의 시각을 1985년 3월 3일 오전 3시 3분 55초로 정합니다.
bash
touch -t 198503030303.55 program.c
영어 원문
  1. To update the access and modification times of a file, enter:
touch program.c

This sets the last access and modification times of the program.c file to the current date and time. If the program.c file does not exist, the touch command creates an empty file with that name.

  1. To avoid creating a new file, enter:
touch -c program.c
  1. To update only the modification time, enter:
touch -m *.o

This updates the last modification times (not the access times) of the files that end with a .o extension in the current directory. The touch command is often used in this way to alter the results of the make command.

  1. To explicitly set the access and modification times, enter:
touch -c -t 02171425 program.c

This sets the access and modification dates to 14:25 (2:25 p.m.) February 17 of the current year.

  1. To use the time stamp of another file instead of the current time, enter:
touch -r file1 program.c

This gives the program.c file the same time stamp as the file1 file.

  1. To touch a file using a specified time other than the current time, enter:
touch -t 198503030303.55 program.c

This gives the program.c file a time stamp of 3:03:55 a.m. on March 3, 1985.

파일

파일 설명
/usr/bin/touch touch 명령이 들어 있습니다.

관련 명령어: date

영어 원문
  • /usr/bin/touch — Contains the touch command.

Related information:

  • date command
  • Directories command
  • Understanding File Types
  • Trusted AIX®
  • RBAC in AIX Version 7.1 Security

리눅스(GNU)와 다른 점

항목 AIX 5.3·6.1 GNU touch
-f 권한과 상관없이 시도 받지만 무시
옛 형식 MMDDhhmm[YY] 받음 POSIX 모드에서만 받음
2038년 이후 5.3은 받지 않음, 6.1은 네 자리 연도로 받음 64비트 시간이면 받음

AIX 5.3·6.1 문서에는 -d "문자열"(자유 형식 날짜), -h(심볼릭 링크 자체), --time= 같은 GNU 플래그가 없습니다.