Tuesday, October 26, 2021

How to use tail to view real-time log data in Linux 101

Must Read

The tail command makes it easy to view log entries as they are written in real-time. Jack Wallen shows you how to make use of this indispensable tool.

One of the best ways to use log files to troubleshoot a system is by viewing the log in real-time. As the logging system writes entries to the log file, it makes it considerably easier to see what’s going on in such a way as to help discern what’s causing the problem.

One of the single most helpful tools in your Linux admin arsenal is log files. And with the open-source platform, there are quite a few different log files to view. But how do you get the most out of your viewing?

The other option is to open the log file and either scroll through it or search it for specific strings. Personally, I much prefer the real-time option.

Let me show you how to use this command.

To view a log file in such a way, there’s a handy command available, called tail. According to the tail man page, tail will print the last 10 lines of each file to standard output. In simplest terms, tail prints out the most recent entries to a file as they are written.

Open a terminal window on your server (or secure shell into a server). Let’s say you want to follow the input to the syslog file. If you issue the command:tail /var/log/syslog, you’ll see the last 10 lines of input written to the file. That’s not exactly real-time, but at least it’s easier to comb through than if you were to view the entire contents of the file.

To view syslog in real-time, you’d add the follow option to the command, as in tail -f /var/log/syslog. This would print out the last 10 lines written to syslog, but would keep updating it as input is written.

By using tail this way, you can see (in real-time) as errors and information are written to the logfile. To close tail, use the Ctrl+C keyboard combination. And that’s all there is to using the tail command to more easily view the content of your log file, or view it as it is written in real-time. This tool will very soon become your go-to for troubleshooting on the Linux operating system.

News Summary:

  • How to use tail to view real-time log data in Linux 101
  • Check all news and articles from the latest Security news updates.
Disclaimer: If you need to update/edit this article then please visit our help center. For Latest Updates Follow us on Google News

More Articles Like This

Latest News