Q:

How to grep recursively in order of last modified time?

grep -r  does a recursive search in all files in a particular directory. However, if I want these files to be read by grep in the order of their last modified time, how do I do that? 

A:

With zsh:
grep -- foo **/*(D.om)

With GNU tools:
find . -type f -printf '%T@\t%p\0' |
  tr '\n\0' '\0\n' |
  sort -rg |
  cut -f2- |
  tr '\n\0' '\0\n' |
  xargs -r0 grep foo

