
Linux에 파일의 모든 타임스탬프를 확인하는 명령이 있습니까?
파일의 마지막 수정, 생성, 터치 날짜를 보려고 합니다.
답변1
명령이 호출됩니다.stat
.
$ stat test
234881026 41570368 -rw-r--r-- 1 werner staff 0 0 "Feb 7 16:03:06 2012" "Feb 7 16:03:06 2012" "Feb 7 16:03:06 2012" "Feb 7 16:03:06 2012" 4096 0 0 test
출력은 OS별로 다르며 Linux/Unix에 따라 다르므로 형식을 조정하려면 매뉴얼 페이지를 참조하세요.
일반적으로 일반 디렉터리 목록을 통해서도 시간을 확인할 수 있습니다.
ls -l
파일 내용이 마지막으로 수정되었을 때 출력됩니다.mtime
ls -lc
파일 상태가 마지막으로 수정된 시간을 출력합니다ctime
.차이점이 뭐야?)ls -lu
마지막 액세스 시간을 출력합니다.atime
(이 개념의 유용성은토론의 대상)
물론 ctime
파일이 "생성"된 시기는 기록되지 않습니다. POSIX 사양은 타임스탬프를 3개만 정의하지만일부 Linux 파일 시스템생성 시간/생성 시간을 저장합니다.파일 생성 날짜를 찾는 방법은 무엇입니까?이러한 지원되는 구성에서는 다음을 사용할 수 있습니다.
stat --printf '%n\nmtime: %y\nctime: %z\natime: %x\ncrtime:%w\n'
답변2
거기 엔 오직삼다음에 정의된 대로 각 파일에 대해 저장된 고유한 시간 값POSIX 표준:http://pubs.opengroup.org/onlinepubs/9699919799/(보다기본 정의섹션 -> 4. 일반 개념 -> 4.8 파일 시간 업데이트)
각 파일에는 세 가지 고유한 관련 타임스탬프가 있습니다.데이터 접근, 마지막 시간데이터 수정, 그리고 시간은파일 상태가 마지막으로 변경됨. 이러한 값은 에 설명된 대로 파일 특성 구조 struct stat에 반환됩니다.<sys/stat.h>.
그리고<sys/stat.h>:
atime is for Last data access timestamp.
mtime is for Last data modification timestamp.
ctime is for Last file status change timestamp.
다음 예는시간,시간그리고c시간, 이러한 예는 GNU/Linux BASH에 있습니다. stat -x
Mac OS X 또는 기타 BSD Dist에서 사용할 수 있습니다 . 비슷한 출력 형식을 보려면
$ stat --version
stat (GNU coreutils) 8.4
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Michael Meskes.
$
$ touch test
$ stat test
File: `test'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 811h/2065d Inode: 98828525 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 514/ rank) Gid: ( 514/ rank)
Access: 2014-03-16 10:58:28.609223953 +0800
Modify: 2014-03-16 10:58:28.609223953 +0800
Change: 2014-03-16 10:58:28.609223953 +0800
파일이 방금 생성되면 세 개의 타임스탬프가 동일합니다.
1. 시간
먼저,입장파일의 데이터를 읽거나( less
또는 vim
) 인쇄하거나( cat
) 다른 파일에 복사( cp
)하여 데이터를 읽을 수 있습니다.
$ cat test #Nothing will be printed out, since the file is empty
$ stat test
File: `test'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 811h/2065d Inode: 98828525 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 514/ rank) Gid: ( 514/ rank)
Access: 2014-03-16 10:59:13.182301069 +0800 <-- atime Changed!
Modify: 2014-03-16 10:58:28.609223953 +0800
Change: 2014-03-16 10:58:28.609223953 +0800
2. c타임
이제변화chmod
권한을 변경( )하거나 이름을 변경( mv
) 하여 파일 상태
$ chmod u+x test
$ stat test
File: `test'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 811h/2065d Inode: 98828525 Links: 1
Access: (0764/-rwxrw-r--) Uid: ( 514/ rank) Gid: ( 514/ rank)
Access: 2014-03-16 10:59:13.182301069 +0800
Modify: 2014-03-16 10:58:28.609223953 +0800
Change: 2014-03-16 11:04:10.178285430 +0800 <-- ctime Changed!
$
$ mv test testing
$ stat testing
File: `testing'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 811h/2065d Inode: 98828525 Links: 1
Access: (0764/-rwxrw-r--) Uid: ( 514/ rank) Gid: ( 514/ rank)
Access: 2014-03-16 10:59:13.182301069 +0800
Modify: 2014-03-16 10:58:28.609223953 +0800
Change: 2014-03-16 11:06:33.342207679 +0800 <-- ctime Changed again!
지금까지의 내용(데이터) 파일의 내용은 생성 당시와 동일합니다.
3. 엠타임
마지막으로수정하다파일을 편집하여 파일의 내용을 확인합니다.
$ echo 'Modify the DATA of the file' > testing
$ echo 'Modify the DATA of the file also change the file status' > testing
$ stat testing
File: `testing'
Size: 56 Blocks: 8 IO Block: 4096 regular file
Device: 811h/2065d Inode: 98828525 Links: 1
Access: (0764/-rwxrw-r--) Uid: ( 514/ rank) Gid: ( 514/ rank)
Access: 2014-03-16 10:59:13.182301069 +0800
Modify: 2014-03-16 11:09:48.247345148 +0800 <-- mtime Changed!
Change: 2014-03-16 11:09:48.247345148 +0800 <-- ctime also Changed!
4. 출생 시간
또한 최신 버전 stat
(예: stat --version 8.13
Ubuntu 12.04)에는 4번째 타임스탬프가 있습니다.출생 시간(파일 생성 시간). 현재로서는 정확한 시간이 표시되지 않을 수도 있습니다.
$ stat --version
stat (GNU coreutils) 8.13
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Michael Meskes.
$
$ stat birth_time
File: `birth_time'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 805h/2053d Inode: 4073946 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ bingyao) Gid: ( 1000/ bingyao)
Access: 2014-03-16 10:46:48.838718970 +0800
Modify: 2014-03-16 10:46:48.838718970 +0800
Change: 2014-03-16 10:46:48.838718970 +0800
Birth: -