2017년 11월 24일 금요일

리눅스의 timestamp

리눅스의 timestamp는 3가지가 있다.

예전 글에도 ctime과 mtime의 차이점에 대해 썼었는데, 그에 대한 연장선이다.

Access(atime) - 파일을 마지막으로 읽은 시간
Modify(mtime) - 파일 내용이 마지막으로 바뀐 시간
Change(ctime) - 파일의 메타 데이터가 마지막 으로 변경된 시간 (e.g. 권한)

 

stat 명령어로 timestamp를 확인 할 수 있다.

toucth 명령어로 test.txt 파일을 하나 생성 후 확인
[root@df test]# touch test.txt
[root@df test]# stat test.txt
File: `test.txt'
Size: 0 Blocks: 0 IO Block: 4096 일반 빈 파일
Device: fd00h/64768d Inode: 68752651 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2017-11-23 17:36:11.380000000 +0900
Modify: 2017-11-23 17:36:11.380000000 +0900
Change: 2017-11-23 17:36:11.380000000 +0900
Birth: -

처음 생성시 Access, Modify, Change가 모두 동일 한 걸 볼 수 있다.

 

touch 명령어로 Access 수정 후 확인.
[root@df test]# touch -a -d '1 Jan 2000 12:34' test.txt
[root@df test]# stat test.txt
File: `test.txt'
Size: 0 Blocks: 0 IO Block: 4096 일반 빈 파일
Device: fd00h/64768d Inode: 68752651 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2000-01-01 12:34:00.000000000 +0900
Modify: 2017-11-23 17:36:11.380000000 +0900
Change: 2017-11-23 17:39:18.467000000 +0900
Birth: -

 

touch 명령어로 Modify 수정 후 확인.
[root@df test]# touch -m -d '1 Jan 2006 12:34' test.txt
[root@df test]# stat test.txt
File: `test.txt'
Size: 0 Blocks: 0 IO Block: 4096 일반 빈 파일
Device: fd00h/64768d Inode: 68752651 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2000-01-01 12:34:00.000000000 +0900
Modify: 2006-01-01 12:34:00.000000000 +0900
Change: 2017-11-23 17:39:52.616000000 +0900
Birth: -

 

권한 변경후 확인(Change)
[root@df test]# chmod 777 test.txt 
[root@df test]# stat test.txt
File: `test.txt'
Size: 0 Blocks: 0 IO Block: 4096 일반 빈 파일
Device: fd00h/64768d Inode: 68752651 Links: 1
Access: (0777/-rwxrwxrwx) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2000-01-01 12:34:00.000000000 +0900
Modify: 2006-01-01 12:34:00.000000000 +0900
Change: 2017-11-23 17:40:18.557000000 +0900
Birth: -

 

cat 명령어로 해당 파일을 읽어 확인.
[root@df test]# cat test.txt 
[root@df test]# stat test.txt
File: `test.txt'
Size: 0 Blocks: 0 IO Block: 4096 일반 빈 파일
Device: fd00h/64768d Inode: 68752651 Links: 1
Access: (0777/-rwxrwxrwx) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2017-11-23 17:48:21.985000000 +0900
Modify: 2006-01-01 12:34:00.000000000 +0900
Change: 2017-11-23 17:40:18.557000000 +0900
Birth: -

Access 만 변경 된 걸 볼 수 있다.

 

echo 명령어로 내용 추가 후 확인.
[root@df test]# echo test >> test.txt 
[root@df test]# stat test.txt
File: `test.txt'
Size: 5 Blocks: 8 IO Block: 4096 일반 파일
Device: fd00h/64768d Inode: 68752651 Links: 1
Access: (0777/-rwxrwxrwx) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2017-11-23 17:48:21.985000000 +0900
Modify: 2017-11-23 17:50:20.241000000 +0900
Change: 2017-11-23 17:50:20.241000000 +0900
Birth: -

Access는 그대로, Modify와 Change가 같이 변했다.

 

그니까 find로 파일 내용이 변경된 파일을 찾으려면 mtime을 이용해야 한다.
# 수정한지 20일 이상( -mtime +20 )된 파일과 디렉토리
find . -mtime +20 -ls

댓글 1개: