Monday, May 6, 2024
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 1616  / 1 Year ago, mon, november 28, 2022, 8:56:21

I have a folder with huge number of files and I want to extract files present with certain text XYZ created within a date range.


I found this to search files within a date range, but unsure how to club it with the specific text filter.


find /MY_DIR/ -newermt "2017-12-01" ! -newermt "2021-01-31"

More From » command-line

 Answers
0

The proper way is to add an -exec option.


find /MY_DIR/ -type f -newermt "2017-12-01" ! -newermt "2021-01-31" -exec grep -l XYZ {} +

Also added -type f option to only look for regular files, not directories, sockets, etc.


[#1981] Tuesday, November 29, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
itchlos

Total Points: 486
Total Questions: 115
Total Answers: 110

Location: Macau
Member since Fri, Apr 28, 2023
1 Year ago
;