How can I find a file that was created within X minutes of a another file?
I'm searching for a non-blank file (other than a header value) and want to find all other files created within 1 minute (or X minutes) of that file.
So far I 开发者_StackOverflow中文版have:
tail -n +2 `ls -rt *.csv | tail -n 1` > watch_me.txt
Which will trim off the first line of the last created csv file. If watch_me.txt is non-blank then I want to find all files that were created within 1 minute (or X minutes) of the csv file that I'm searching for.
This command will find all files in the current directory that were modified withing 60 sec (+ or -) from modification time of file watch_me.txt
ts=$(stat --printf="%Y" watch_me.txt);
tsmin=$(date -d @$((ts-60)));
tsmax=$(date -d @$((ts+60)));
find . -maxdepth 1 -newermt "$tsmin" -not -newermt "$tsmax"
Will a simple
ls -alt
i.e sort according to the files modification time suffice?
Then a grep
using either -A
or -B
switch to extract
the matching lines after or before a matching file.
精彩评论