linux - Grep inside all files created within date range -
i on ubuntu os. want grep word (say xyz) inside log files created within date range 28-may-2012 30-may-2012.
how that?
this little different banthar's solution, work versions of find don't support -newermt , shows how use xargs command, useful tool.
you can use find command locate files "of age". find files modified between 5 , 10 days ago:
find /directory -type f -mtime -10 -mtime +5 to search files string:
find /directory -type f -mtime -10 -mtime +5 -print0 | xargs -0 grep -l expression you can use -exec switch, find xargs more readable (and perform better, too, possibly not in case).
(note -0 flag there let command operate on files embedded spaces, such this filename.)
update question in comments
when provide multiple expressions find, anded together. e.g., if ask for:
find . -name foo -size +10k ...find return files both (a) named foo and (b) larger 10 kbytes. similarly, if specify:
find . -mtime -10 -mtime +5 ...find return files (a) newer 10 days ago and (b) older 5 days ago.
for example, on system currently:
$ date fri aug 19 12:55:21 edt 2016 i have following files:
$ ls -l total 0 -rw-rw-r--. 1 lars lars 0 aug 15 00:00 file1 -rw-rw-r--. 1 lars lars 0 aug 10 00:00 file2 -rw-rw-r--. 1 lars lars 0 aug 5 00:00 file3 if ask "files modified more 5 days ago (-mtime +5) get:
$ find . -mtime +5 ./file3 ./file2 but if ask "files modified more 5 days ago less 10 days ago" (-mtime +5 -mtime -10), get:
$ find . -mtime +5 -mtime -10 ./file2
Comments
Post a Comment