简体   繁体   中英

find files within a time range plus one additional file

I need to get some files picked up in a time range plus one file more with linux board tools like "find".

Let me give an example: I need all files modified between "2018-06-06 10:27:24" and "2018-06-06 16:43:47" and one file created after that timestamp. My problem is. I only get the information about these two timestamps and the next file created after the second timestamp could be created at any time. one minute or one week after the second timestamp.

My most elegant try was something like:

find /FOLDER -name "*MYPATTERN*" -newermt "2018-06-06 10:27:24" ! -newermt "2018-06-06 16:43:47"

But with this solution there is no plus one additional file and I cannot find a nice solution so far.

Best regards neik

perhaps in two steps

$ find ... -newermt "{latest_timestamp}" -printf "%TY%Tm%Td%TH%TM%TS\t%p\n" | 
  sort -nr | awk -F'\t' '{print $2; exit}'

will give you one file updated after the latest_timestamp.

Or, instead of manually setting the date/time to be sortable numerically just use %@T as suggested by @Socowi in the comments.

Add an "or" clause to your current find command:

t1="2018-06-06 10:27:24"
t2="2018-06-06 16:43:47"

find /FOLDER \( -name "*MYPATTERN*" -newermt "$t1" ! -newermt "$t2" \) \
          -o \( -name '*THE_EXTRA_FILE*' -newermt "$t2" \)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM