How to Grep Logs Based on Timestamp

How to Grep Logs Based on Timestamp

I need logs only from 09:36 to 09:39 in server logs where the timestamp is 2019-03-19T09:37:19 like this. Can anyone suggest me grep command for this

1

2 Answers

grep '2019-03-19T09:3[6-9]' /var/log/syslog

Because you said your timestamp is 2019-03-19T09:37:19. I suggest you do:

  1. Press CTRL + ALT + T.
  2. Run the command (-E for extended regex):

    sudo grep -E '2019-03-19T09:3[6-9]' <file or file_path>
    

To be direct, the above command could be (if run immediately after CTRL + ALT + T or another path):

sudo grep -E '2019-03-19T09:3[6-9]' /var/log/syslog

Or (if in /log/ folder already...):

sudo grep -E '2019-03-19T09:3[6-9]' syslog

I hope that's clear enough to help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Alexander Ross
Author

Alexander Ross

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.