How can I find/list all python scripts that are younger than a certain date and containing a certain word? I would also like to print the modification date in front of each file name if possible.

So far I tried this but it is also showing java files:

find . -type f -name "*.py" -newermt "2019-01-01" | grep -Ri "Distribution"

You can execute the grep on each file using -exec and print the name and other information only if it succeeds:

find . -type f -name "*.py" -newermt "2019-01-01" -exec grep -qi "Distribution" {} \; -printf '%Tx %p\n'
  • Worked like a charm, thank you :) – SuperKogito Apr 28 '19 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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