1

Files are created at regular interval with the name which do not contain any timestamp.

How can I grep/filter any text from these files created in last 24 hours or with creation date of the files?

/data/logs/file*.log
fedorqui
  • 252,262
  • 96
  • 511
  • 570
Raka
  • 11
  • 1
  • 2
  • so did my answer work to you? If so, remember you can accept it by clicking on the check mark beside the answer to toggle it from hollow to green. See [Help Center > Asking](http://stackoverflow.com/helpcenter/someone-answers) if you have any doubt! – fedorqui Jan 12 '15 at 10:49

1 Answers1

7

You can use find to get the files in /data/logs/ on the form file*log that were modified on the last 24 hours:

find /data/logs/ -mtime -1 -name file*log

Then, just grep through exec:

find /data/logs  -mtime -1 -name file*log -exec grep "whatever" {} \;

If you also want to show the filename, use -H as suggested by Mark Setchell --> ... -exec grep -H "whatever" {} \;.

Credits to Scripts: find the files have been changed in last 24 hours.

Community
  • 1
  • 1
fedorqui
  • 252,262
  • 96
  • 511
  • 570