tail -f prints the new lines of a log file as they are written. less +F follows the file the same way, but lets you stop with Ctrl+C to search and resume with Shift+F. On a production server, tail -n 200 -f gives you prior context, and grep --line-buffered filters the stream without delaying output.
tail -n 200 -f: get context before following the log
tail -n 200 -f /var/log/nginx/error.log prints the last 200 lines of the file and then waits for new ones. Without -n, tail shows only 10, which is rarely enough to see what happened right before an error.
tail -n 200 -f /var/log/nginx/error.log
tail -n 200 -F /var/log/syslog
journalctl -u nginx -n 200 -fThe difference between -f and -F matters once logrotate is involved. -f follows the open file descriptor. If rotation renames the file, tail keeps reading the old one, which no longer grows. -F is equivalent to --follow=name --retry and reopens the file by name when it is recreated. For services that log to journald, journalctl -f does the same job. In every case you exit with Ctrl+C. The full option list is in the tail manual page.
less +F: follow a log, then stop to search without quitting
less +F opens the file and runs less's F command on startup. That command jumps to the end and waits for new data, just like tail -f. The payoff comes when you press Ctrl+C: following stops, but you stay inside less with the whole file available to search.
less +F /var/log/nginx/access.log
# Inside less:
# Ctrl+C stop following; you can scroll now
# /502 search forward for '502' (n = next match)
# ?timeout search backward
# &error show only matching lines
# F resume following the end
# q quitThis workflow fits a real incident. A suspicious line scrolls past, so you press Ctrl+C. You search backward for the first warning with ?. When you are done, you resume following with F (Shift+F). With tail -f you would have to quit, run another command and lose your place. For files that logrotate rotates, less supports --follow-name, which makes F reopen the file by name. Details are in the full less manual.
grep --line-buffered: filter tail -f without pipeline delays
grep uses block buffering when its output is not a terminal. In a chain like tail -f | grep | tee, matches can therefore show up late or arrive in bursts. --line-buffered forces grep to flush its output after every line.
tail -n 200 -f /var/log/nginx/access.log | grep --line-buffered ' 502 ' | tee 502.log
tail -n 200 -F /var/log/syslog | grep --line-buffered -E 'error|crit|oom'If grep is the last command and writes straight to the screen, you do not need the flag, because it already works line by line. It becomes necessary as soon as grep's output feeds another program or a file. The spaces around ' 502 ' cut down on matches against numbers that merely contain 502. tee saves a copy of the filtered stream while you keep watching it.
multitail and tail -f with several files: two logs at once
tail -f accepts several files and prints a ==> name <== header whenever output switches source. That is enough to correlate access and error logs for the same service.
tail -n 50 -f /var/log/nginx/access.log /var/log/nginx/error.log
# multitail splits the screen into windows, one per file
sudo apt install multitail
multitail /var/log/nginx/access.log /var/log/nginx/error.logmultitail is rarely preinstalled; it is available in the Debian and Ubuntu repositories. By default it stacks windows on top of each other. On a phone held upright, that layout works better than -s 2, which places them in columns. Press q to quit. With more than two files on a phone screen, each window gets so short that plain tail -f with several files is the better choice.
tail -f vs less +F and multitail: comparison table
tail -f is the only one of the three you will find on any Unix-like system without installing anything. less ships with most distributions, and multitail needs to be installed.
| Tool | Best for | How to pause or exit | On a phone screen |
|---|---|---|---|
| tail -n 200 -f | Watching new lines and piping into grep | Ctrl+C returns to the prompt | Works well; only needs a Ctrl key |
| less +F | Following, pausing and searching backward | Ctrl+C pauses, F resumes, q quits | Needs Ctrl and Shift+F; PgUp/PgDn to scroll |
| multitail | Several logs in separate windows | q quits | Fine with two files; more becomes unreadable |
| tail -f with several files | Correlating two logs in one stream | Ctrl+C returns to the prompt | Headers take up lines; acceptable in portrait |
Following logs with tail -f from a phone: keys, Mosh and tmux
Ctrl+C, Shift+F, Esc and PgUp/PgDn are the keys you use most when reading logs, and the system keyboard on iOS and Android hides most of them. The termi1 keyboard adds Esc, Ctrl, Tab and arrow keys. It also has an fn layer with F1–F12, PgUp/PgDn, Home and End, which is handy for moving around inside less.
- Network changes: a plain SSH session drops when you move from Wi-Fi to mobile data, and your
tail -fdies with it. Mosh keeps the session alive: it uses UDP, by default on ports 60000-61000, and startsmosh-serverthrough an initial SSH connection. - Long-running follows: run the follow inside tmux so you can pick it up later. Start a session with
tmux new -s logsand runtail -n 200 -F. Detach with Ctrl+B then D, and come back withtmux attach -t logs. - Full log files: if you need to read an entire file at your own pace, termi1's built-in SFTP downloads it without leaving the session.
- Dictated commands: termi1's AI turns 'follow the nginx error log and filter 502s' into a command typed at the prompt without pressing Enter, so you can review it first. On connections tagged as production, Production Guard ensures nothing receives Enter automatically.
The termi1 SSH and Mosh terminal works without an account and can generate SSH keys on the phone itself. The keys are stored in the system's secure storage, and the private key never leaves the device. You can get termi1 on the App Store or on Google Play.
Frequently asked questions
How do I exit tail -f without closing the SSH session?
To exit tail -f, press Ctrl+C: it stops following and returns you to the prompt with the SSH session still open. On a phone you need a keyboard with a Ctrl key. The system keyboard on iOS and Android does not include one, which is why terminal apps add their own key row.
What is the difference between tail -f and tail -F?
The difference between tail -f and tail -F is what they follow. tail -f follows the open file descriptor and keeps reading the old file after rotation. tail -F is equivalent to --follow=name --retry: it reopens the file by name when logrotate recreates it and keeps showing new lines.
Why does grep show nothing when piped after tail -f?
grep shows nothing when piped after tail -f because, when its output goes to another pipe or a file, it holds results in a block buffer. The --line-buffered flag forces grep to write each matching line as soon as it finds it, so matches appear in real time.
How do I keep tail -f running and reattach from my phone?
To keep tail -f running and reattach from your phone, start it inside a tmux session created with tmux new -s logs, then detach with Ctrl+B followed by D. Later, tmux attach -t logs brings the follow back exactly where it was, even if your connection dropped in between.