Skip to content
Log In Sign Up info@muvcloud.com

The tail Commands You Will Use Most

sudo tail /var/log/nginx/error.log
sudo tail -n 100 /var/log/nginx/error.log
sudo tail -f /var/log/nginx/access.log
sudo tail -F /var/log/nginx/access.log

Without options, tail prints the last 10 lines. -n 100 prints the last 100. -f follows the file and prints new lines until you press Ctrl+C. -F does the same and keeps following when the log is rotated. Many logs in /var/log are readable only by root, so use sudo.

Choose How Much to Show

OptionWhat it shows
-n 50The last 50 lines
-n +200Everything from line 200
-c 1KThe last 1024 bytes

For the start of a file, use head, which takes the same -n option.

Follow a Log Live

Open the log in one terminal, then reload the page or repeat the action in a browser or a second terminal. New lines appear as they are written. This is the fastest way to see which error a request causes.

sudo tail -n 0 -f /var/log/nginx/error.log

-n 0 starts with an empty screen, so everything you see is new.

Why -F Is Better for Logs

Log files are rotated regularly: logrotate renames access.log to access.log.1 and a new access.log starts. tail -f follows the file it opened, so after rotation it keeps watching the old, renamed file and shows nothing new. tail -F follows the name: it notices the new file and continues with it. Use -F for anything you leave open for a long time.

Watch Several Files

sudo tail -F /var/log/nginx/access.log /var/log/nginx/error.log

tail prints a header line with the file name, such as ==> /var/log/nginx/error.log <==, each time the output switches to another file. -q hides these headers.

Filter What You See with grep

sudo tail -F /var/log/nginx/access.log | grep " 404 "
sudo tail -F /var/log/nginx/access.log | grep --line-buffered " 500 " | tee errors.txt

The first command shows only lines with status 404. When grep writes to another program or a file instead of the screen, it collects lines in a buffer and output appears late; --line-buffered makes it pass each line on at once. To count or rank what you see, see awk and sort and uniq.

Logs in the systemd Journal

Many services write to the systemd journal instead of a file. On some installs, /var/log/syslog or /var/log/messages does not exist at all. The journal has its own follow mode:

sudo journalctl -f
sudo journalctl -u nginx -f
sudo journalctl -u ssh -n 50

-u limits the output to one service and -n sets how many past lines to show. The SSH service is named ssh on Debian and Ubuntu and sshd on AlmaLinux and Rocky Linux.

Follow a Log in less

sudo less +F /var/log/nginx/error.log

less in follow mode works like tail -f, but Ctrl+C stops following without closing the file. You can then scroll back and search with /. Press F to follow again and q to quit.

Where Common Logs Are

  • Nginx: /var/log/nginx/, the files access.log and error.log.
  • Logins: /var/log/auth.log on Ubuntu and Debian, /var/log/secure on AlmaLinux and Rocky Linux, when a syslog service writes them.
  • Full disk: if logs grow too large, see how to check disk space in Linux; do not delete active logs by hand.

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations