Touch

touch는 파일의 날짜와 시간을 수정하는 명령어이다.

아무런 옵션 없이 사용하면 서버의 현재 시간으로 파일의 최근 사용한 시각(access time)과 최근 변경 시각(modification time)을 변경한다. 만약 특정옵션이 사용되지 않는다면 파일의 크기가 0인 빈 파일을 생성한다. -t 라는 옵션을 사용하면 서버의 현재 시간이 아닌 지정된 시간으로 파일의 날짜 시간 정보를 변경한다.

리눅스의 모든 파일은 네가지 시간을 가진다.

리눅스에는 세 종류의 타임스탬프가 있다.

  • Access time : 어떤 앱에 의해 마지막으로 접근된 시간
  • Modification time : 마지막으로 내용이 수정된 시간
  • Changed time : 마지막으로 파일의 메타데이타, 특성, 내용이 변경된 시간
  • Birth time : 파일이 만들어진 시간
$stat test.txt
Access: 2023-07-30 21:33:48.207773129 +0900
Modify: 2023-07-21 00:00:00.000000000 +0900
Change: 2023-07-30 21:32:55.767834971 +0900
 Birth: 2023-07-21 23:40:39.805987832 +0900

stat 명령어로 볼 수 있다.

$ touch [파일명]

별다른 옵션이 없다면 atime, ctime, mtime 모두 변경된다.

  • -a Used to change only the access time.
  • -m Used to change only the modification time.
  • -d Used to update the access and modification times.
  • -c Do not create a new file, if the does not exist.
  • -r Used to use the access and modification times of another file.
  • -t Used to create a file with a specified time.