After we published "Linux Tail Command - Everything You Need to Know" we received quite a few questions. Most of them were asking how to tail multiple files at once. In this Linux quick tip we will show you a few ways to tail -f (follow) multiple files.
Tail Multiple Files with Native Tail Command
The easiest way to accomplish this, without installing any additional software, is to use the tail command with multiple files as arguments.
Example:
tail -f file1 file2
$ tail -f access.log httpd.log ==> access.log <== 109.224.11.34 - - [15/May/2015:18:32:56 +0100] "GET… 109.169.248.247 - - [15/May/2015:22:25:11 +0100] "GET… 109.169.248.247 - - [15/May/2015:22:25:11 +0100] "POST… 46.72.177.4 - - [15/May/2015:22:31:08 +0100] "GET… 46.72.177.4 - - [15/May/2015:22:31:08 +0100] "POST… ==> httpd.log <== 46.72.177.4 - - [15/May/2015:18:31:08 +0100] "POST… 83.167.113.100 - - [15/May/2015:18:31:25 +0100] "GET… 83.167.113.100 - - [15/May/2015:18:31:25 +0100] "POST… 95.29.198.15 - - [15/May/2015:18:32:10 +0100] "GET… 95.29.198.15 - - [15/May/2015:18:32:11 +0100] "POST… 109.184.11.34 - - [15/May/2015:18:32:56 +0100] "GET…
You can also tail multiple files with different options like so:
tail -F /var/log/messages -f /var/log/messages
To learn about the available options read "Linux Tail Command - Everything You Need to Know".
Using multitail Utility to Tail Multiple Files
The multitail utility allows you to tail multiple files and output in the terminal. Mutlitail provides most of the popular options of native tail and it adds additional functionality like tee command simulation, colorization, filtering and the ability to merge output. It also provides options for customized screen layouts. Multitail is available to many Linux distributions and can easily be installed with your package manager.
Install multitail with DNF
In Fedora you can simply use DNF to install the package like so:
sudo dnf install multitail
Install multitail with Yum
For Red Hat or CentOS 7, you must install the epel repository first:
sudo yum install epel-release sudo yum install multitail
Install multitail with APT
In Ubuntu and Debian variants you can use apt-get like so:
sudo apt-get install multitail
Multitail Basic Usage
To tail multiple files with multitail simply invoke the program followed by the two filenames you wish to follow.
$ multitail access.log httpd.log
The nice thing about multitail is it creates two panes, one for each file. These panes can scroll independently and search works across both panes.
Multitail is a feature rich utility and would need it's own complete tutorial to even begin to scratch the surface. For more information and options visit the man pages listed in the resources section.
Conclusion
In this Linux quick tip we showed you how to tail multiple files with the tail command. We also outlined some of the benefits of using an optional tool called multitail. Both have their pros and cons, but now you know, and knowing is half the battle.