linux 장비에서 디렉토리가 패치되었는지 확인하려고 ls -l 로 시간을 봤는데 뭔가 이상했다.

$ ls -l test.txt
-rwxrwxrwx 1 user user 42 Apr 25 22:49 test.txt

ls -l 을 사용했을 때 보이는 시간은 mtime (Modify Time)이다. 파일이 마지막으로 수정된 시간이라고 한다.

$ mv test.txt test2.txt
$ ls -l test2.txt
-rwxrwxrwx 1 user user 42 Apr 25 22:49 test2.txt

파일을 이동시킨 경우 파일 시간이 변경되지 않는다.

$ ls -lc test2.txt
-rwxrwxrwx 1 user user 42 May 17 23:39 test2.txt

파일 이동 같은 경우 ctime (Change Time) 이 변경된다. -c 옵션을 이용하면 파일 시간으로 ctime 이 표시된다.

$ ls -lu test2.txt
-rwxrwxrwx 1 user user 42 May 17 23:44 test2.txt

atime (Access Time) 같은 경우 cat 이나 tail 같은 명령어로 파일을 여는 것 만으로도 갱신될 수 있다고 하는데 최근 linux 들은 그렇지 않은 것 같다. atime 은 -u 옵션을 사용하면 확인할 수 있다.

$ stat test2.txt
  File: test2.txt
  Size: 42              Blocks: 0          IO Block: 512    regular file
Device: 30h/48d Inode: 1125899906999448  Links: 1
Access: (0777/-rwxrwxrwx)  Uid: ( 1000/    user)   Gid: ( 1000/    user)
Access: 2022-05-17 23:44:26.969102000 +0900
Modify: 2022-05-17 23:44:26.969102000 +0900
Change: 2022-05-17 23:44:26.969102000 +0900
 Birth: -

모든 시간 옵션을 보고 싶으면 stat 명령어를 사용하면 된다.

$ touch -a test2.txt
$ ls -lu test2.txt
-rwxrwxrwx 1 user user 42 May 17 23:51 test2.txt
$ stat test2.txt
  File: test2.txt
  Size: 42              Blocks: 0          IO Block: 512    regular file
Device: 30h/48d Inode: 1125899906999448  Links: 1
Access: (0777/-rwxrwxrwx)  Uid: ( 1000/    user)   Gid: ( 1000/    user)
Access: 2022-05-17 23:51:50.716797800 +0900
Modify: 2022-05-17 23:44:26.969102000 +0900
Change: 2022-05-17 23:51:50.716797800 +0900
 Birth: -

파일 시간 변경을 위해 touch 명령을 이용할 수 있다. -a 옵션을 이용해 atime 을 변경할 수 있다.

참고 : https://hbase.tistory.com/297

 

[Linux] atime, ctime, mtime 차이점

리눅스 파일에는 'atime', 'ctime', 'mtime' 3가지 시간 정보가 있다. 각각 Access Time, Change Time, Modify Time을 의미하는 시간이다. 파일 시스템에서 파일을 조회하거나 수정 날짜를 확인할 때, 이 세 가지..

hbase.tistory.com

http://choesin.com/%EC%84%A4%EB%AA%85-%EB%90%9C-linux-%ED%8C%8C%EC%9D%BC-%ED%83%80%EC%9E%84-%EC%8A%A4%ED%83%AC%ED%94%84-atime-mtime-%EB%B0%8F-ctime

 

설명 된 Linux 파일 타임 스탬프 : atime, mtime 및 ctime - 최신

Fatmawati Achmad Zaenuri / 셔터 스톡 “변경된”은 언제 “수정 된”을 의미하지 않습니까? Linux 파일 타임 스탬프에 대해 이야기 할 때 이 가이드에서는 시스템이 시스템을 업데이트하는 방법과 직접

choesin.com

 

728x90

+ Recent posts