How to tail multiple files at once in Linux

Last updated on June 8, 2020 by Dan Nanni

If you are a Linux system administrator, monitoring log files on a server host will be one of your daily routines. The tail command comes in handy as you can monitor a log file in real-time as it grows, by running tail with -f option.

What if you want to monitor more than one log file at the same time? You could run tail on multiple terminals, or launch multiple instances of tail in one terminal by using terminal multiplexers such as screen. But neither approach is convenient in monitoring mupltiple log files at once.

In this post, I will describe how to tail multiple files at once in Linux, by using a command-line tool called multitail.

multitail creates ncurses-based multiple screens inside a terminal, each of which can run a separate instance of tail-like file viewer.

Install multitail on Linux

For Ubuntu or Debian:

To install multitail on Ubuntu or Debian:

$ sudo apt-get install multitail

For Fedora:

To install multitail on Fedora:

$ sudo yum install multitail

For CentOS or RHEL:

To install multitail on CentOS or RHEL, first set up Repoforge on your system, and then run:

$ sudo yum install multitail

Monitor Log Files with multitail

In the following, I illustrate several common use cases of multitail command.

1. Monitor multiple log files as they grow in horizontally-split screens.

The terminal screen will automatically be split into the number of log files specified.

$ sudo multitail --follow-all /var/log/auth.log /var/log/kern.log /var/log/syslog

2. Monitor multiple log files as they grow in vertically-split screens.

Use "-s N" option to vertically split the screen into N columns.

$ sudo multitail -s 3 --follow-all /var/log/auth.log /var/log/kern.log /var/log/syslog

3. Monitor multiple command outputs simultaneously

Besides tailing log files, multitail can also monitor the output of an external command whiles the execution of the command is in progress. For this, use "-l "command-to-run"" option. For example, you can run multiple ping commands, and monitor individual ping outputs simultaneously in split screens as follows.

$ multitail -l "ping twitter.com" -l "ping google.com"

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal (Credit Card) or Bitcoin (1M161JGAkz3oaHNvTiPFjNYkeABox8rb4g).

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean