So are you saying that you want to search for some strings/patterns inside files that are newer than July 1st 2023?
If so, try this:
Bash:
find ./ -maxdepth 1 -type f -newermt 2023-07-01 -exec grep -iHn --color searchstring {} +
Where searchstring is the actual string you want to search for in the file.
If you want to search for something else - then replace searchstring with a string or regular expression that describes what you're looking for in the file.
The above command will use
find
to find ALL files in the current directory (without recursing into any sub-directories) that are newer than July 1st 2023.
Each file that is found is then ran through grep, to search for the string "searchstring".
Because we've used
grep
's
-i
flag, the search will be case-insensitive - if you want the search to be case sensitive - remove the
-i
flag.
The
-H
flag ensures that the filename is listed next to each result from grep, so you know which file the pattern was found in. The
-n
flag shows the line-number for the lines that matched the pattern. And the
-color
will highlight the matches in colour, so you can see which parts of the line matched the pattern. Again, if any of these flags are NOT required, feel free to remove them.
In
find
's
-exec
section - the
{}
is a placeholder for the path/filename of files that were found by
find
. And the
+
at the end tells
find
to append any other found files at the end of the command line.
This will cause the
grep
command in the
-exec
section to be ran once, with a list of ALL of the files found.
Alternatively, the
-exec
section could look like this:
Code:
-exec grep -iHn --color searchstring {} \;
If you end the
-exec
with
\;
, then the
grep
command will be ran each time a file is found. But if you have 100 files - grep will be ran 100 times.
I hope this is useful!