简体   繁体   中英

How can I sort the results of a recursive directory grep search (grep -rl )?

I want to sort the results of grep -rl 'string' . by create date or modification date.

find . -type f -cmin -90 |xargs ls -1t |xargs grep -l "pattern"
  • find does recursive part and initial cut-off to ensure you don't get too many files (changed in last 90 minutes here)
  • ls does the sort ( -t ) and output one file by line ( -1 )
  • grep list the names of file that match the pattern

And of course xargs is what passes output of one command as parameters to another. Which is why you want to pre-filter the list with find to avoid having too many.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM