Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to grep all files that have a keyword and files should be created today

Have a directory with files. how to grep all files with a particular keyword and files should be created today.

tried this :


grep -r -n "pass" *.json

this gives the line number and only searches json file but how to add pipe to search for only files that are created today

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use the find command as the source of the list of files to search.

grep -n "pass" $(find . -daystart -ctime 0 -name '*.json')

-ctime says "creation date should have been 0 days ago", and -daystart says to base it on the beginning of the day for "days ago", not "24 hours ago" ago.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading