How to make tail display only the lines that have a specific text?

Use tail together with grep. Pipe the output of tail into grep and specify the text (or pattern) you want to keep.

Examples

- Show the last 10 lines that contain “ERROR”:

bash<br>tail -n 10 logfile | grep "ERROR"<br>

- Continuously follow a growing file but only display lines that contain “warning”:

bash<br>tail -f logfile | grep "warning"<br>

- Show the last 200 lines and filter for the word “success” (case‑insensitive):

bash<br>tail -n 200 logfile | grep -i "success"<br>

The grep part does the filtering, so only the lines that match the specified text are printed.

Sign In Name Sign Out