grep files based on time stamp

后端 未结 3 909
情歌与酒
情歌与酒 2021-02-04 13:13

This should be pretty simple, but I am not figuring it out. I have a large code base more than 4GB under Linux. A few header files and xml files are generated during build (usin

相关标签:
3条回答
  • 2021-02-04 13:43

    You could use the find command:

    find . -mtime 0 -type f
    

    prints a list of all files (-type f) in and below the current directory (.) that were modified in the last 24 hours (-mtime 0, 1 would be 48h, 2 would be 72h, ...). Try

    grep "pattern" $(find . -mtime 0 -type f)
    
    0 讨论(0)
  • 2021-02-04 14:04

    Use this. Because if find doesn't return a file, then grep will keep waiting for an input halting the script.

    find . -mtime 0 -type f | xargs grep "pattern"
    
    0 讨论(0)
  • 2021-02-04 14:06

    To find 'pattern' in all files newer than some_file in the current directory and its sub-directories recursively:

    find -newer some_file -type f -exec grep 'pattern' {} +
    

    You could specify the timestamp directly in date -d format and use other find tests e.g., -name, -mmin.

    The file list could also be generate by your build system if find is too slow.

    More specific tools such as ack, etags, GCCSense might be used instead of grep.

    0 讨论(0)
提交回复
热议问题