how to find files modified between 2 timestamps on Linux
Solution1: find
It is implemented with a find command on Linux.
$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.5 (Maipo)
$ ls -la --time-style=full-iso file*
-rw------- 1 root root 4 2019-06-26 11:55:50.517172461 +0900 file__20190626115550.dat
-rw------- 1 root root 4 2019-06-26 11:56:00.886213308 +0900 file__20190626115600.dat
-rw------- 1 root root 7 2019-06-26 11:56:13.604262638 +0900 file__20190626115613.dat
-rw------- 1 root root 7 2019-06-26 11:56:18.006279403 +0900 file__20190626115618.dat
$ find . -type f -newermt "20190626 11:56:00" -and ! -newermt "20190626 11:56:14"
./file__20190626115600.dat
./file__20190626115613.dat
注意:閾値を含む。
$ find . -type f -newermt "20190626 11:56:00" -and ! -newermt "20190626 11:56:13"
./file__20190626115600.dat
MACでは
$ ls -lT *
-rw-r--r-- 1 akirasakaguchi staff 2 6 26 14:37:03 2019 file_20190626_143703.dat
-rw-r--r-- 1 akirasakaguchi staff 2 6 26 14:37:09 2019 file_20190626_143709.dat
-rw-r--r-- 1 akirasakaguchi staff 2 6 26 14:37:11 2019 file_20190626_143711.dat
-rw-r--r-- 1 akirasakaguchi staff 2 6 26 14:37:12 2019 file_20190626_143712.dat
$ find . -type f -newermt "20190626 14:37:09" -and ! -newermt "20190626 14:37:11"
./file_20190626_143711.dat
注意:閾値を含まない。
Solution2: find and diff
$ find . -type f -newermt "20190626 11:56:00"./file__20190626115600.dat
./file__20190626115613.dat
./file__20190626115618.dat
$ find . -type f -newermt "20190626 11:56:14"
./file__20190626115618.dat
$ find . -type f -newermt "20190626 11:56:00" >../list1
$ find . -type f -newermt "20190626 11:56:14" >../list2
$ diff --old-line-format="%L" --new-line-format="" --unchanged-line-format="" ../list1 ../list2
./file__20190626115600.dat
./file__20190626115613.dat
コメント
コメントを投稿