How to View the Last Lines of a File in Linux

Use tail to inspect recent log entries and control how many lines you see.

Large log files are rarely useful from the beginning. `tail` starts at the end, where the newest entries normally are, making it one of the first commands to reach for during troubleshooting.

Step by step

1 Show the last 10 lines

$ tail app.log

Ten lines is the default.

2 Show a specific number

$ tail -n 50 app.log

Displays the last 50 lines.

3 Show the last bytes

$ tail -c 2000 app.log

Useful when you need a byte-sized slice rather than a line count.

4 Follow new entries

$ tail -f app.log

Keeps the command running and prints new data as it is appended.

Tips worth knowing

Frequently asked questions

How do I see the last 100 lines of a file?

Use `tail -n 100 file.txt`.

What is the difference between tail and head?

tail reads from the end; head reads from the beginning.

How do I watch a log file live?

Use `tail -f app.log` or `tail -F app.log` when the file may be rotated.

The commands behind it

head & tail

Print the first or last lines of a file — including live log following with tail -f.

less

The standard pager: scroll, search, jump — and follow logs from inside.

grep

Find lines matching a pattern in files or piped input — the workhorse of text search.

More how-to guides

Check disk space in Linux

See how much space is left, and find out what is using it.

Extract a .tar.gz archive

Unpack tar.gz, tar.bz2, tar.xz and zip archives from the command line.

Free a port that is already in use

Find which process holds a port and stop it cleanly.

Find and replace text in files

Replace text in one file or across a whole project, safely.