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


$ tail -f /var/log/syslog -f /var/log/auth.log


$ 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

# When this exits, exit all back ground process also.
trap 'kill $(jobs -p)' EXIT

# iterate through the each given file names,
for file in "$@"
	# show tails of each in background.
	tail -f $file &

# wait .. until CTRL+C

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

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

{ 22 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
tail -f filename2

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!


$ mutitail error_log access_log

should be


$ multitail error_log access_log

7 emmerich September 10, 2009 at 3:15 pm

I do the following …

tail -f filename1 filename2 &
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


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


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.


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


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


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

13 alex March 8, 2012 at 3:13 am

for SunOS I had to change
trap ‘kill $(jobs -p)’ EXIT
trap ‘kill $(jobs -p)’ 2

14 alex March 8, 2012 at 3:15 am

… and changed to #!/usr/bin/bash

15 Zilore Mumba April 29, 2012 at 6:17 am

If i may ask for help on a rather different topic:
I have a bash script to replace dates in
start_date = ’2012-04-23_00:00:00′,’2012-04-23_00:00:00′,
end_date = ’2012-04-25_00:00:00′,’2012-04-25_00:00:00′,
In my script below replaces the words “start_date and end_date”. How do I define the dates as replacement patterns? Will appreciate any help.

ystart=`date “+%Y”`
mstart=`date “+%m”`
dstart=`date “+%d”`

YYYYMMDDstart=`date -u +%Y-%m-%d`

YYYYend=`date –date=’2 days’ -u +%Y`
MMend=`date –date=’2 days’ -u +%m`
DDend=`date –date=’2 days’ -u +%d`

YYYYMMDDend=`date –date=’2 days’ -u +%Y-%m-%d`
echo ${YYYYMMDDend}${HHMMSS}

cat namelist.wps.dailyGFS | sed s/start_date/${YYYYMMDDstart}${HHMMSS}/g > namelist.wps.tmp
cat namelist.wps.tmp | sed s/end_date/${YYYYMMDDend}${HHMMSS}/g > namelist.wps
rm namelist.wps.tmp

16 Carlos Estensser May 19, 2012 at 11:25 am

Great tips. Thanks.

17 Stephen Z May 29, 2012 at 3:44 am

I don’t really understand why you’d script this… my mac and linux machines can follow multiple files simultaneously without any special tricks.

tail -f file1 file2 file3
will follow all 3 files

You can also wildcard.

tail -f /var/log/*log

18 Milind December 28, 2012 at 12:04 pm

Thanks for this post, it was really helpful to me. I have a question on terminating tail -f processes. Normally, when I exit any tail -f command using ctrl +C, it still leaves the process running in background and I have to kill it separately by kill command. Is there any way to exit so that the process associated with this command is also terminated and I don’t have to explicitly kill it?

19 Jimmy August 28, 2013 at 1:46 pm

On Solaris 10, I changed:

trap ‘kill $(jobs -p)’ EXIT


trap ‘pgrep tail|xargs kill’ 2

20 nisav November 7, 2013 at 11:03 am

This was very helpful

But I want to tail logs in different folders :


I want to know if I can do something like this in just one line :
tail -f /var/*/file.log

Tail all file.log files inside the sub folders under /var

21 no screen June 14, 2014 at 6:26 pm

Screen lets you save sessions and log back into them later – no use for monitoring multiple files at the same time in the same window.

Did not know about multiple files after the tail -f command, though, so this is very useful! Thanks!

22 Matt August 24, 2014 at 8:29 am

You can use the asterisk wildcard too, for example tail -f /var/log/*

Leave a Comment

Previous post:

Next post: