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"

2 Answers 2


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.


If you would like to find some text within those files just use grep like this:

grep -i "XYZ" `find /MY_DIR/ -newermt "2017-12-01" ! -newermt "2021-01-31"`

The -i switch makes it case insensitive.

The grep at the start of the line will look for text in files.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.