Bash / Debian에서 파일 생성 날짜 / 시간을 얻는 방법은 무엇입니까?
Debian GNU / Linux 6.0에서 Bash를 사용하고 있습니다. 파일 생성 날짜 / 시간을 알 수 있습니까? 수정 날짜 / 시간이 아닙니다. ls -lh a.txt
그리고 stat -c %y a.txt
둘은 수정 시간을 제공합니다.
불행히도 POSIX 표준에 정의 된대로 각 파일에 대해 3 개의 고유 한 시간 값만 저장되어 있으므로 일반적으로 퀘스트를 수행 할 수 없습니다 ( 기본 정의 섹션 4.8 파일 시간 업데이트 참조 ).
각 파일에는 마지막 데이터 액세스 시간, 마지막 데이터 수정 시간 및 파일 상태가 마지막으로 변경된 시간의 세 가지 고유 한 연관된 타임 스탬프가 있습니다. 이러한 값은 <sys / stat.h>에 설명 된대로 파일 특성 구조 struct stat에 반환됩니다 .
편집 : 아래 설명에서 언급했듯이 사용 된 파일 시스템에 따라 메타 데이터에 파일 생성 날짜가 포함될 수 있습니다. 그러나 이와 같은 정보의 저장은 표준이 아닙니다. 그것에 따라 실제로 사용 된 파일 시스템이 어쨌든 저장하는 경우 다른 파일 시스템으로 이동하는 이식성 문제가 발생할 수 있습니다.
ls -i file #output is for me 68551981
debugfs -R 'stat <68551981>' /dev/sda3 # /dev/sda3 is the disk on which the file exists
#results - crtime value
[root@loft9156 ~]# debugfs -R 'stat <68551981>' /dev/sda3
debugfs 1.41.12 (17-May-2010)
Inode: 68551981 Type: regular Mode: 0644 Flags: 0x80000
Generation: 769802755 Version: 0x00000000:00000001
User: 0 Group: 0 Size: 38973440
File ACL: 0 Directory ACL: 0
Links: 1 Blockcount: 76128
Fragment: Address: 0 Number: 0 Size: 0
ctime: 0x526931d7:1697cce0 -- Thu Oct 24 16:42:31 2013
atime: 0x52691f4d:7694eda4 -- Thu Oct 24 15:23:25 2013
mtime: 0x526931d7:1697cce0 -- Thu Oct 24 16:42:31 2013
**crtime: 0x52691f4d:7694eda4 -- Thu Oct 24 15:23:25 2013**
Size of extra inode fields: 28
EXTENTS:
(0-511): 352633728-352634239, (512-1023): 352634368-352634879, (1024-2047): 288392192-288393215, (2048-4095): 355803136-355805183, (4096-6143): 357941248-357943295, (6144
-9514): 357961728-357965098
미키 라의 대답은 좋다. 그가 말한 것과 같은 사실.
[jason@rh5 test]$ stat test.txt
File: `test.txt'
Size: 0 Blocks: 8 IO Block: 4096 regular empty file
Device: 802h/2050d Inode: 588720 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 500/ jason) Gid: ( 500/ jason)
Access: 2013-03-14 01:58:12.000000000 -0700
Modify: 2013-03-14 01:58:12.000000000 -0700
Change: 2013-03-14 01:58:12.000000000 -0700
파일이 먼저 생성되었는지 확인하려면 일련의 파일을 생성 할 때 시스템 날짜를 추가하여 파일 이름을 구성 할 수 있습니다.
성능상의 이유로 파일 시스템을 noatime으로 마운트 한 경우 atime에 생성 시간이 표시 될 가능성이 높습니다. noatime은 (파일을 읽을 때마다 디스크 쓰기를 제거함으로써) 엄청난 성능 향상을 가져 오므로 원하는 결과를 제공하는 합리적인 구성 옵션 일 수 있습니다.
생성 날짜 / 시간은 일반적으로 저장 되지 않습니다 . 그래서 아니, 당신은 할 수 없습니다.
ls -i menus.xml
94490 menus.xml 여기서 숫자 94490은 inode를 나타냅니다.
그런 다음 다음을 수행하십시오.
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg-root 4.0G 3.4G 408M 90% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 124M 27M 92M 23% /boot
/dev/mapper/vg-var 7.9G 1.1G 6.5G 15% /var
파일 menus.xml이 '/ dev / mapper / vg-root'인 '/'에 있기 때문에 루트 "/"파일 시스템의 마운트 지점을 찾으려면
debugfs -R 'stat <94490>'/ dev / mapper / vg-root
출력은 다음과 같을 수 있습니다.
debugfs -R 'stat <94490>'/ dev / mapper / vg-root
debugfs 1.41.12 (17-May-2010)
Inode: 94490 Type: regular Mode: 0644 Flags: 0x0
Generation: 2826123170 Version: 0x00000000
User: 0 Group: 0 Size: 4441
File ACL: 0 Directory ACL: 0
Links: 1 Blockcount: 16
Fragment: Address: 0 Number: 0 Size: 0
ctime: 0x5266e438 -- Wed Oct 23 09:46:48 2013
atime: 0x5266e47b -- Wed Oct 23 09:47:55 2013
mtime: 0x5266e438 -- Wed Oct 23 09:46:48 2013
Size of extra inode fields: 4
Extended attributes stored in inode body:
selinux = "unconfined_u:object_r:usr_t:s0\000" (31)
BLOCKS:
(0-1):375818-375819
TOTAL: 2
생성 시간을 볼 수있는 곳 :
ctime: 0x5266e438 -- Wed Oct 23 09:46:48 2013
사용 - 출생 시간 일명 - 당신은 생성 시간을 찾을 수 합계를 또한 사용하여 일치 찾기 .
마지막 수정 시간을 보여주는 다음 파일이 있습니다.
$ ls -l --time-style=long-iso | sort -k6
total 692
-rwxrwx---+ 1 XXXX XXXX 249159 2013-05-31 14:47 Getting Started.pdf
-rwxrwx---+ 1 XXXX XXXX 275799 2013-12-30 21:12 TheScienceofGettingRich.pdf
-rwxrwx---+ 1 XXXX XXXX 25600 2015-05-07 18:52 Thumbs.db
-rwxrwx---+ 1 XXXX XXXX 148051 2015-05-07 18:55 AsAManThinketh.pdf
사용하여 특정 시간 프레임 내에서 생성 된 파일을 찾으려면 찾기를 다음과 같이한다.
분명히 파일 시스템은 파일의 생성 시간을 알고 있습니다.
$ find -newerBt '2014-06-13' ! -newerBt '2014-06-13 12:16:10' -ls
20547673299906851 148 -rwxrwx--- 1 XXXX XXXX 148051 May 7 18:55 ./AsAManThinketh.pdf
1407374883582246 244 -rwxrwx--- 1 XXXX XXXX 249159 May 31 2013 ./Getting\ Started.pdf
We can confirm this using stat:
$ stat -c "%w %n" * | sort
2014-06-13 12:16:03.873778400 +0100 AsAManThinketh.pdf
2014-06-13 12:16:04.006872500 +0100 Getting Started.pdf
2014-06-13 12:16:29.607075500 +0100 TheScienceofGettingRich.pdf
2015-05-07 18:32:26.938446200 +0100 Thumbs.db
stat man pages explains %w:
%w time of file birth, human-readable; - if unknown
As @mikyra explained, creation date time is not stored anywhere.
All the methods above are nice, but if you want to quickly get only last modify date, you can type:
ls -lit /path
with -t option you list all file in /path odered by last modify date.
If you really want to achieve that you can use a file watcher like inotifywait.
You watch a directory and you save information about file creations in separate file outside that directory.
while true; do
change=$(inotifywait -e close_write,moved_to,create .)
change=${change#./ * }
if [ "$change" = ".*" ]; then ./scriptToStoreInfoAboutFile; fi
done
As no creation time is stored, you can build your own system based on inotify.
Cited from https://unix.stackexchange.com/questions/50177/birth-is-empty-on-ext4/131347#131347 , the following shellscript would work to get creation time:
get_crtime() {
for target in "${@}"; do
inode=$(stat -c %i "${target}")
fs=$(df "${target}" | tail -1 | awk '{print $1}')
crtime=$(sudo debugfs -R 'stat <'"${inode}"'>' "${fs}" 2>/dev/null | grep -oP 'crtime.*--\s*\K.*')
printf "%s\t%s\n" "${target}" "${crtime}"
done
}
even better:
lsct ()
{
debugfs -R 'stat <'`ls -i "$1" | (read a b;echo -n $a)`'>' `df "$1" | (read a; read a b; echo "$a")` 2> /dev/null | grep --color=auto crtime | ( read a b c d;
echo $d )
}
lsct /etc
Wed Jul 20 19:25:48 2016
Another trick to add to your arsenal is the following:
$ grep -r "Copyright" /<path-to-source-files>/src
Generally speaking, if one changes a file they should claim credit in the “Copyright”. Examine the results for dates, file names, contributors and contact email.
example grep result:
/<path>/src/someobject.h: * Copyright 2007-2012 <creator's name> <creator's email>(at)<some URL>>
참고URL : https://stackoverflow.com/questions/14842195/how-to-get-file-creation-date-time-in-bash-debian
'Program Tip' 카테고리의 다른 글
Rails 콘솔이 lib에서 모듈을 다시로드 할 수 있습니까? (0) | 2020.11.26 |
---|---|
링크 위로 마우스를 가져갈 때 나타나는 손 모양 커서를 제거 할 수 있습니까? (0) | 2020.11.26 |
벡터 드로어 블을 미리 볼 수있는 방법이 있습니까? (0) | 2020.11.26 |
멤버 식의 값에 액세스 (0) | 2020.11.26 |
“LINQ 식 노드 유형 'Invoke'는 LINQ to Entities에서 지원되지 않습니다.”-당황했습니다! (0) | 2020.11.26 |