Linux Command Collection

Find the log file, find a certain string, and display the current line and the first two lines of the matched string, and only display the first 20 lines of the total number of lines queried:
grep -B 2 'Read operation to server 10.10.1.100: 27017 failed' -m 20 catalina.20160223.out

grep -C 5 foo file show the line in the file that matches the foo string and 5 lines above and below
grep -B 5 foo file show foo and the first 5 lines
grep -A 5 foo file show foo and the last 5 lines

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326737198&siteId=291194637