Bash 5 reference · Text and System Tools

head and tail (Linux command)

Show the first or last lines of files, skip headers, and follow growing log files with tail -f.

Bash 5

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

head [-n N] FILE   tail [-n N|+N] [-f] FILE

Parameters

ParameterDescription
-n N Number of lines.
tail -n +2 From line 2 onward (skip a header).
-f / -F Follow new lines (-F survives rotation).

Examples

First and last lines
seq 1 10 > n.txt
head -n 2 n.txt | tr '\n' ' '; echo
tail -n 2 n.txt | tr '\n' ' '; echo

Output

1 2 
9 10 

Run this on your computer — see “Get Started” for setup.

Skip a CSV header
printf 'id,name\n1,ana\n2,ben\n' | tail -n +2

Output

1,ana
2,ben

Run this on your computer — see “Get Started” for setup.

Was this page helpful?