logo
search
list

Table of Content

Basic Syntax
Show a Specific Number of Lines (-n)
Follow a Growing File (-f and -F)
Multiple Files in One Terminal
Bytes Instead of Lines (-c)
Pipelines: Filter While Following
Head vs Tail
Common Pitfalls
Quick Cheat Sheet
From Terminal Logs to Shareable Documents
FAQ

Tail Command in Linux: View & Follow Log Files (Ubuntu)

Posted by Algirdas Jasaitis

calendar

2026-07-24

views

869

likes

4

The tail command in Linux prints the last part of a file—by default the last 10 lines. It is part of GNU coreutils on Ubuntu and is the everyday tool for checking recent log output and watching files as they grow (-f / -F).

man tail
tail --version

Official reference: Ubuntu man page tail(1). With no file (or -), tail reads standard input. If you already know your goal, jump to: -n, -f/-F, multiple files, or grep pipelines. To print a whole short file, use cat instead.

Concept illustration of the Linux tail -f command following a growing syslog file in a terminal
Tail shows the end of a file—use -n for line count, -f to follow, and -F when logs rotate.

Basic Syntax

tail [OPTION]... [FILE]...
tail /var/log/syslog          # last 10 lines
tail notes.txt

With more than one file, GNU tail prints a header (==> filename <==<>) before each file’s output.

Show a Specific Number of Lines (-n)

tail -n 20 /var/log/syslog    # last 20 lines
tail -20 /var/log/syslog      # short form (GNU)

Start from a given line number with +:

# Skip the first 99 lines; print from line 100 onward
tail -n +100 bigfile.txt

Follow a Growing File (-f and -F)

Watch new lines as they are appended (Ctrl+C to stop):

tail -f /var/log/syslog
tail -f app.log

From the man page:

ModeBehavior
-f / --followFollow by file descriptor (default). If the file is renamed, tail still follows the old inode.
-FSame as --follow=name --retry—follow by name, reopen after rotation/unlink.
# Better for rotated logs (logrotate)
tail -F /var/log/nginx/access.log

Other useful follow options:

tail -f -s 2 app.log              # sleep ~2s between checks
tail -f --pid=1234 app.log        # stop when PID 1234 exits (GNU)
tail -f --retry missing.log       # keep trying if file is inaccessible

Multiple Files in One Terminal

Ask Ubuntu tip—pass several paths to one tail -f:

tail -f /var/log/syslog /var/log/auth.log

Headers label which file each block came from. Alternatives: multitail, tmux/screen splits, or terminal tabs.

tail -q -n 5 a.log b.log     # -q: quiet (no headers)
tail -v file.txt             # -v: always show headers

Bytes Instead of Lines (-c)

tail -c 100 file.bin         # last 100 bytes
tail -c +200 file.txt        # from byte 200 to end

NUM can use suffixes like K, M (see man tail).

Pipelines: Filter While Following

For grep flags and buffering details beyond this page, see the grep command in Linux guide.

Common Ask Ubuntu pattern—follow then filter:

tail -f my_file.log | grep "X"

Chaining two greps can look “stuck” because of buffering. Fixes:

tail -f /path/to/log | grep --line-buffered 'X' | grep -v 'Y'
# or
tail -f /path/to/log | stdbuf -oL grep 'X' | grep -v 'Y'
# or one awk rule
tail -f /path/to/log | awk '/X/ && !/Y/'

Also useful:

dmesg | tail -n 30
journalctl -u ssh -n 50      # systemd: often better than raw files
journalctl -f -u nginx       # follow a unit (alternative to tail -f)

Head vs Tail

CommandShows
headBeginning of a file
tailEnd of a file
tail -f / -FLive end of a growing/rotated file
head -n 20 file.txt
tail -n 20 file.txt

Need the full file contents or to join files? That is cat's job—not tail.

Common Pitfalls

ProblemWhat to try
Log rotates and -f “stops”Use tail -F (follow by name + retry)
tail -f | grep | grep silent--line-buffered / stdbuf -oL / awk
Live USB / overlayfs odditiesSome filesystems break inotify; see Ask Ubuntu workarounds
Huge noisy logstail -n first, then -f with grep
Need service-centric logsPrefer journalctl -f -u … on systemd

Stop a follow session with Ctrl+C. In scripts, prefer tail --pid=$$ -f … so follow ends when the parent process exits.

Quick Cheat Sheet

tail file                     # last 10 lines
tail -n 50 file               # last 50 lines
tail -n +100 file             # from line 100
tail -f file                  # follow (descriptor)
tail -F file                  # follow name (rotation-safe)
tail -f a.log b.log           # multiple files
tail -c 1K file               # last 1K bytes
tail -f log | grep --line-buffered ERROR
tail -f --pid=$PID app.log

From Terminal Logs to Shareable Documents

tail and tail -f belong in the terminal. After you isolate the failing lines, the next step is often a short incident note, a timestamp table, or a PDF for teammates still on Microsoft Office. For that handoff, use a desktop suite—not another pager.

WPS Office for Linux covers Writer, Spreadsheet, Presentation, and PDF tools on Ubuntu and other mainstream distributions, so the report you write on Linux opens cleanly for Windows colleagues.

WPS Office Writer on a Linux desktop editing an Incident Report DOCX with a familiar ribbon toolbar
WPS Office Writer on a Linux desktop editing an Incident Report DOCX with a familiar ribbon toolbar
What you need after tailWhat WPS gives you
Keep charts, tables, and slides intact in Office filesStrong .docx / .xlsx / .pptx layout fidelity when exchanging with Windows or macOS
One app for notes, sheets, slides, and PDFFree core suite: Writer, Spreadsheet, Presentation, plus PDF view/edit/convert
A familiar UI on a modest laptopRibbon-style desktop apps with a lighter footprint than many heavyweight suites
A trusted install pathOfficial DEB (Ubuntu/Debian/Mint) and RPM packages—no random mirrors

Get the current 64-bit build from the official WPS Office for Linux download page (choose Deb on Ubuntu), then install the local file—replace VERSION with the name you downloaded:

cd ~/Downloads
sudo apt install ./wps-office_VERSION_amd64.deb

Open Writer, paste the snippet you pulled with tail and grep, and save as DOCX or export PDF so formatting survives the handoff. Keep tail for watching services; use WPS when those lines need to become a real document your team can open anywhere.

Use Word, Excel, and PPT for FREE

FAQ

What does the tail command do in Linux?
It prints the last part of a file (default: 10 lines), and can follow new data as the file grows.

What is the difference between tail -f and tail -F?
-f follows the open file descriptor; -F follows the filename and retries—better when logs are rotated.

How do I show the last 100 lines?
tail -n 100 filename

How do I follow two logs at once?
tail -f /var/log/syslog /var/log/auth.log

Why did my grep pipeline stop updating?
Output buffering—use grep --line-buffered or stdbuf -oL.

Where is the official documentation?
Run man tail or see the Ubuntu tail(1) man page.

Algirdas Jasaitis

15 years of office industry experience, tech lover and copywriter. Follow me for product reviews, comparisons, and recommendations for new apps and software.