Linux 101: How to easily view real-time log entries with tail
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 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?
SEE: 5 Linux server distributions you should be using (TechRepublic Premium)
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.
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.
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.
SEE: Rust: What developers need to know about this programming language (free PDF) (TechRepublic)
Let me show you how to use this command.
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.
Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.
We are now on Telegram. Click here to join our channel (@TechiUpdate) and stay updated with the latest Technology headlines.
For all the latest Technology News Click Here