tail
Read the last lines of a log, skip a CSV header with tail -n +2, and watch a log live with tail -f.
>_ Try it: a simulated Linux, right herenothing runs on your computer
Loading the terminal…
Examples
-
tail app.log -
tail -n 3 app.log -
tail -n +2 users.csv -
grep ERROR app.log | tail -n 1 -
tail -f app.log
How it works
tail FILE prints the last 10 lines. Logs grow at the bottom, so that is where the newest — and usually the interesting — lines are.
tail -f keeps the file open and prints each new line as it is written: the classic way to watch a server while you test it. Ctrl+C stops it.
Syntax
tail [-n [+]LINES] [-f] [FILE]...
Options
| Option | What it does |
|---|---|
-n N | the last N lines instead of 10 |
-n +N | everything from line N on (skips the first N−1) |
-f | follow: keep printing new lines as they arrive |
Good to know
- On a server,
tail -f /var/log/syslog(orjournalctl -f) in one window while you restart a service in another shows you what happens, live. - In this simulator nothing writes to files while you watch, so
tail -fprints the end and stops; on a real machine it waits until you press Ctrl+C.