Custom Search

SUBSCRIBE

SUBSCRIBE : 300 + Free Video Tutorials Programming (Python, golang, Julia), DevOps

Wednesday, February 3, 2016

How to search in log files

1)
Search in all log files under /var/log/contrail

$for x in $(sudo ls /var/log/contrail); do sudo cat /var/log/contrail/$x | grep "Search me"; done

OR

$sudo find /var/log/contrail -type f -exec grep 'Search me' {} \;

a)
Find file name
$sudo find /var/log/contrail -type f -exec grep -l 'Search me' {} \;

b)
Find line number
$sudo find /var/log/contrail -type f -exec grep -n 'Search me' {} \;

2)
Find all log files which are updated within last 2 minutes, then search for a pattern

$for x in $(sudo find /var/log/contrail *.log -mmin -2); do sudo cat $x | grep "Search me"; done

3)
Find all log files which are updated within last 2 minutes, then search for a pattern in las 100 lines

$for x in $(sudo find /var/log/contrail *.log -mmin -2); do sudo tail -n 100 $x | grep "Search me"; done

4)
How to read portion of huge file (from line number to line number)

$Y=359975 --- From line number
$X=359880 --- To line number
$tail -n +$X /var/log/contrail/contrail-api-0-stdout.log.10 | head -n $((Y-X+1))

5)







No comments:

Post a Comment