gareth asked this 4 years ago

Ubuntu: Extract log within a period

How to get all the log entries in the last 2 hours?

I am running apache on Ubuntu.

sonja 4 years ago

Use grep -E "pattern" logfile

Option -E is for extended regular expression.

So at 13 hrs, you could grep for 13, 12 to give you last 2 hr period

grep -E "Jan 27 (13|12)" /var/log/syslog