Linux command list

tail command: show the end of a file

__ __ _ _____
\ \ / /__| |_|_ _|__ _ __ _ __ ___
\ \ /\ / / _ \ '_ \| |/ _ \ '__| '_ ` _ \
\ V V / __/ |_) | | __/ | | | | | |
\_/\_/ \___|_.__/|_|\___|_| |_| |_| |_
 
A sandbox for trying tail. Nothing here can touch your real files.
user@webterm:~/project$
 

tail prints just the end of a file. Learn the default of ten lines, how to set the count with -n, and how -f follows a log as it is written, by running the commands in a real terminal in your browser.

Updated: 2026-09-05

Syntax

tail [options] file...

Prints the end of a file. Without a count, that means ten lines.

Try it first

The terminal on this page has a log file with 30 lines in it.

$ tail logs/app.log
line 21
line 22
line 23
line 24
line 25
line 26
line 27
line 28
line 29
line 30

The last ten lines. This is the useful end of a log, because new lines are appended at the bottom.

Choosing how many lines

-n takes the count.

$ tail -n 3 logs/app.log
line 28
line 29
line 30

Right after something breaks, this is the first thing to look at.

Counting from the start instead

Put a + in front of the number and the meaning flips. It is no longer a count from the end, it is from that line onwards.

$ tail -n +28 logs/app.log
line 28
line 29
line 30

Following a live log

-f keeps the file open and prints new lines as they arrive.

tail -f app.log

This is the standard way to watch a running server. Press Ctrl+C to stop.

When you actually reach for it

tail is how you watch what is happening now.

SituationWhat you type
See the error that just happenedtail -n 50 app.log
Follow a running logtail -f app.log
Follow only the errorstail -f app.log | grep ERROR
Skip a header rowtail -n +2 users.csv

Things that trip people up

-f waits for you to stop it. It never returns to the prompt on its own. Ctrl+C ends it.

Short files come out whole.

$ tail -n 2 notes.txt
buy milk
call the bank

If the file has fewer than ten lines, tail and cat show you the same thing.

A file being written can look cut off at the end. You are reading a line that is not finished yet; wait a moment and the rest appears.

Practise it hands-on

webterm.appthis site

  • Advanced Terminal Commands

    Learn commands for specific situations

    Try the tutorial

learn.webterm.appa separate site

>_WEBTERM LEARN

WebTerm Learn: from one command to actually using it

Commands stick when they show up in a real sequence of work, not one at a time. There is a course that builds them up in order.

See the course

Related commands

head / less / cat / grep

Frequently asked questions

How many lines does tail print?
Ten by default. Use -n to ask for a different number.
What does tail -f do?
It keeps the file open and prints new lines as they are written, which is how people watch a running server's log. Press Ctrl+C to stop.
Why is tail the tool for logs?
Logs grow downwards, so what is happening right now is at the end. The beginning is startup noise that rarely helps during an incident.
Can I count from the start instead?
Yes. -n +28 means from line 28 to the end, counted from the beginning rather than the end.
How is it different from head?
head takes the beginning, tail the end. The options are the same, so learning one gives you the other.