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
Syntax
head [-n N] FILE tail [-n N|+N] [-f] FILE
Parameters
| Parameter | Description |
|---|---|
-n N |
Number of lines. |
tail -n +2 |
From line 2 onward (skip a header). |
-f / -F |
Follow new lines (-F survives rotation). |
Examples
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.
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.
Related
grep· Search files or input for lines matching a pattern, with options for case, counts, context, recursion and regex.wc· Count lines, words, characters and bytes in files or input; wc -l is the usual way to count lines or results.- Bash Viewing Files · tutorial