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
- Use `less +G app.log` when you need to inspect the end interactively.
- Combine tail with grep to focus on recent matching entries.
- For rotated logs, make sure you are following the file that the service is actually writing.
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
Print the first or last lines of a file — including live log following with tail -f.
lessThe standard pager: scroll, search, jump — and follow logs from inside.
grepFind lines matching a pattern in files or piped input — the workhorse of text search.
More how-to guides
See how much space is left, and find out what is using it.
Extract a .tar.gz archiveUnpack tar.gz, tar.bz2, tar.xz and zip archives from the command line.
Free a port that is already in useFind which process holds a port and stop it cleanly.
Find and replace text in filesReplace text in one file or across a whole project, safely.