Skip to content
Latchkey

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

Terminal
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 headers

Options

FlagWhat it does
-n NPrint the last N lines
-n +NPrint starting from line N to the end
-c NPrint the last N bytes
-qSuppress filename headers
-fFollow 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.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →