tail show the last lines

tail prints the end of a file, 10 lines by default. It can also start from a given line, which is handy for dropping a header row, and it can follow a log file as it grows.

Availability Preinstalled on macOS, Linux and BSD

Syntax

tail [-n count] [-f] [file ...]

Common options

OptionWhat it does
-n NPrint the last N lines
-n +NPrint everything from line N onwards. -n +2 skips a header row
-fKeep the file open and print new lines as they are written

Examples

Last 20 lines of a log

tail -n 20 app.log

Watch a log live

tail -f app.log

Everything except the header

tail -n +2 users.csv

Use tail with sqx

Combine CSV files that each have a header

Keep the header from the first file only, then append the data rows of every file.

{ head -n 1 january.csv; tail -n +2 january.csv; tail -n +2 february.csv; } | sqx "SELECT COUNT(*) FROM stdin"

Query only the most recent entries

tail -n 500 access.jsonl | sqx "SELECT status, COUNT(*) FROM stdin GROUP BY status"

tail -f never finishes, and sqx waits for the end of its input, so don't pipe tail -f into sqx. Take a fixed number of lines with -n instead.

Full documentation

This page covers the essentials. For every option, see the official documentation:

Or read the manual in your terminal: man tail