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
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 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..
|
|
|
|












My name is Ramesh Natarajan. I will be posting instruction guides, how-to, troubleshooting tips and tricks on Linux, database, hardware, security and web. My focus is to write articles that will either teach you or help you resolve a problem. Read more about
{ 12 comments… read them below or add one }
The output of the second method can be easily customized using grep or sed.
Don’t you think `screen’ would work better?
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
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…
excellent article….
Thanks alot
Typo alert!
”
…
(or)
$ mutitail error_log access_log
”
should be
”
…
(or)
$ multitail error_log access_log
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 <==
..
..
@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.
Tips on how to do this with screen?
I use Terminator: https://launchpad.net/terminator
multi-tail.sh script doesn’t kill tails in the background on my system (debian).
on AIX Method 1: works great, thanks