Typically you may open multiple terminals to view tail -f of multiple files as we explained in our previous 10 examples to view unix log files.
For example, if you want to view Apache error_log and access_log at the same time you may do the following in two different terminals.
On one terminal:
$ tail -f error_log
On another terminal:
$ tail -f access_log
Wouldn’t it be nice if you can execute multiple unix tail command in single terminal using one of the following methods?
$ multi-tail.sh error_log access_log (or) $ tail -f /var/log/syslog -f /var/log/auth.log (or) $ multitail error_log access_log
In this article let us review using three methods how to execute multiple Linux tail -f at the same time in single terminal.
Method 1: Use Custom Shell Script (with Unix tail command)
Create the multitail.sh as shown below.
$ vi multi-tail.sh #!/bin/sh # When this exits, exit all back ground process also. trap 'kill $(jobs -p)' EXIT # iterate through the each given file names, for file in "$@" do # show tails of each in background. tail -f $file & done # wait .. until CTRL+C wait
Now, open multiple files using this new shell script as shown below.
$ ./multi-tail.sh error_log access_log
Method 2: Using the standard Linux tail command
The latest version of the Unix tail command supports multiple -f as shown below.
$ tail -f /var/log/syslog -f /var/log/auth.log
The above will display file name as the first line each time, and then shows the newly grown lines. If you don’t want this to clutter the logs, you can use the next method.
Method 3. Use multitail command on Debian flavor of Linux
Install multitail as shown below.
$ apt-get install multitail
View multitail for multiple file
$ multitail /var/log/syslog /var/log/auth.log
Multitail utility has lot of additional features as explained in the mutitail home page.
- display log files in colors,
- scroll back in a log file,
- search inside log file,
- merge mutliple log files effectively
Get the Linux Sysadmin Course Now!