tail -n: Last N Lines, Including +N
tail -n N prints the last N lines; tail -n +N prints from line N to the end.
tail grabs the end of output, and its +N form is the cleanest way to skip a header row.
What it does
tail -n N writes the final N lines of the input. The plus form, tail -n +N, instead starts output at line N and continues to the end, which is the idiomatic way to drop the first N-1 lines (for example a header).
Common usage
tail -n 50 app.log
tail -n +2 data.csv # skip the header row
git tag | sort -V | tail -n 1 # latest version tag
tail -n +1 *.txt # print files with headersOptions
| Flag | What it does |
|---|---|
| -n N | Print the last N lines |
| -n +N | Print starting from line N to the end |
| -c N | Print the last N bytes |
| -q | Suppress filename headers |
| -f | Follow appended data (see tail -f) |
In CI
tail -n +2 is the simplest header-skipper for CSV and tabular output, cleaner than sed or awk for that single job. Combine with sort -V | tail -n 1 to select the newest tag or release.
Common errors in CI
Confusing -n N with -n +N: the first counts from the end, the second from a line number; mixing them up grabs the wrong slice. Older BSD/macOS tail historically wanted tail -N or tail +N rather than -n N, so prefer the -n form and test on both runner types. Files without a trailing newline can make the last line merge with the prompt.