3 Methods To View tail -f output of Multiple Log Files in One Terminal

by Ramesh Natarajan on September 9, 2009

Linux Tail Command for 2 filesTypically 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

But, wait!

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 on Linux - View multiple log files together

Fig: multitail - Click on the image to enlarge

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

Share

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

{ 12 comments… read them below or add one }

1 sergray September 9, 2009 at 2:28 am

The output of the second method can be easily customized using grep or sed.

2 Dmitri Minaev September 9, 2009 at 2:50 am

Don’t you think `screen’ would work better?

3 Praveen September 9, 2009 at 7:26 am

I do the following …

tail -f filename1
ctrl+z
bg
tail -f filename2
Ctrl+z
bg

jobs //to see what are being run in background

4 Randy September 9, 2009 at 8:01 am

Awesome, I wasn’t aware that “multitail” existed until now.

I would have guessed you were going to also mention the “screen” command here also… :)

5 diptanu September 9, 2009 at 8:25 am

excellent article….

Thanks alot

6 Daniel September 9, 2009 at 10:44 am

Typo alert!


(or)

$ mutitail error_log access_log

should be


(or)

$ multitail error_log access_log

7 emmerich September 10, 2009 at 3:15 pm

I do the following …

tail -f filename1 filename2 &
or
tail -f filename1 filename2

there one can see from which file the message comes.

==>filename1 filename2 <==
..
..

8 Ramesh Natarajan September 10, 2009 at 11:39 pm

@Sergray,

Thanks for your feedback about using grep and sed along with tail -f.

@Dmitry, @Randy,

I agree with you that screen is also another effecient way to view multiple log files on one terminal

@Praveen,

Thanks for sharing your tips. Running tail -f in the background may be OK for two files. Anything more than that, it may get little confusing.

@Daniel,

Thanks for catching the typo. It’s fixed now.

@Emmierich,

Thanks for pointing out the we can view multi files without give -f after each and every file.

@Diptanu,

I’m glad you found this article helpful.

9 Ted September 12, 2009 at 11:50 pm

Tips on how to do this with screen?

10 Ikon February 1, 2010 at 3:30 am
11 matej February 12, 2010 at 12:08 pm

multi-tail.sh script doesn’t kill tails in the background on my system (debian).

12 Anonymous June 25, 2011 at 6:40 am

on AIX Method 1: works great, thanks

Leave a Comment

Previous post:

Next post: