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
  • 275,237
  • 103
  • 548
  • 598
Raka
  • 11
  • 1
  • 2

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
  • 275,237
  • 103
  • 548
  • 598