[tail] Print only the last line

Created on November 30, 2026

Use tail -n 1 to print one line from the end of its input.

printf 'apple\nbanana\norange\n' | tail -n 1
orange

You can pass a file instead of piping input.

tail -n 1 fruits.txt

The number after -n sets how many lines to take from the end.

Reference

Shell command tail