Reputation: 4684
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 (using gnu make). If it matters the header files are generated based on xml files.
I want to search for a keyword in header file that was last modified after a time instance ( Its my start compile time), and similarly xml files, but separate grep queries.
If I run it on all possible header or xml files, it take a lot of time. Only those that were auto generated. Further the search has to be recursive, since there are a lot of directories and sub-directories.
Upvotes: 11
Views: 53683
Reputation: 21
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"
Upvotes: 2
Reputation: 414685
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
.
Upvotes: 12
Reputation: 552
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)
Upvotes: 20