Timestamp grep files

It should be pretty simple, but I do not understand. I have a large code base of over 4 GB on Linux. Several header files and xml files are generated during build (using gnu make). If it is important, header files are created based on xml files.

I want to find a keyword in the header file that was last modified after the time instance (its compilation start time) and similar xml files, but separate grep requests.

If I run it in all possible header or xml files, it takes a lot of time. Only those that were generated automatically. Further, the search should be recursive, since there are many directories and subdirectories.

+6
source share
3 answers

Find 'pattern' in all files above some_file in the current directory and its subdirectories recursively:

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

You can specify the timestamp directly in the format date -d and use other find tags, for example, -name , -mmin .

A list of files can also be generated by your build system if find too slow.

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

+11
source

You can use the find :

 find . -mtime 0 -type f 

prints a list of all files ( -type f ) in and below the current directory ( . ) that have been changed in the last 24 hours ( -mtime 0 , 1 will be 48 hours, 2 - 72 hours, ...). Try

 grep "pattern" $(find . -mtime 0 -type f) 
+11
source

Use this. Because if find does not return the file, then grep will continue to wait for script input.

 find . -mtime 0 -type f | xargs grep "pattern" 
+2
source

Source: https://habr.com/ru/post/905911/


All Articles