Issue
I've a directory with thousands of files, many of them containing the text I'm looking for. I've to search only in a single directory. I need to find the most recently created file in the directory that contains a particular text, say "check".
I've tried grep, find and ls, but I can either find a list of files containing the text e.g.
find . -type f -exec grep -l check {} +
or, the latest file in a directory using:
ls -t1 | head -n 1
How can I combine both to get the latest file containing a particular text?
Solution
I tweeked my initial command to get the desired results. I'm posting here for future searches:
find . -type f | xargs grep -l "text to find" | xargs ls -rt | tail -1
Answered By - SJaka