Linux: How to do an 'effective' "tail -f" on multiple files?

Posted on 2012-09-05
Last Modified: 2012-09-05
Sometimes it would be really useful if you could, in real time, join all the log files (/var/log/* in my distro.) and do a tail -f on them except the ones you exclude from a directory (e.g. .bz2 files).

Has anyone tackled this idea and come up with a solution? I would really like to do this and it's especially useful on new hardware when something weird is going wrong and you are not yet sure where.

Question by:RegProctor
    LVL 68

    Assisted Solution

    There is MultiTail ...
    LVL 1

    Author Comment

    Obviously I mean in one command on one command line, not with multiple shell windows like I do on occasion.

    Some real-time equivalent to a theoretical command like below (which obviously wont work):

    cat --exclude='*.bz2' --exclude='something-else' /var/log/*|tail -n 1

    Open in new window

    (Again, the above is only to ~demonstrate~ what I want to achieve, it won't work.)
    LVL 68

    Expert Comment

    cd /var/log
    tail -n2 -f $(ls -F --ignore="*.bz2" --ignore="wtmp" --ignore="something-else" |egrep -v "/$|@$")
    LVL 19

    Accepted Solution

    +1 for multitail!

    On my system (which has .1 files as the most recent backup, and .n.gz for previous backups) I used:

    multitail --mergeall --follow-all -D $(ls -F --ignore="*.bz2" --ignore="[bw]tmp" --ignore="lastlog" --ignore="*.1" --ignore "*.gz"|egrep -v "/$|@$")

    Open in new window

    It does a "tail -f" of all of the files which don't match any of the exclude patterns, and aren't directories or symlinks.

    This example doesn't put the filename at the start of the line -  I'm sure it's possible but I couldn't see how.
    LVL 1

    Author Closing Comment

    I installed multitail and it's great.

    I've added on more ignore for the log directory from @simon3270 comment which was --ignore="*.old" and it worked perfectly.

    Featured Post

    Courses: Start Training Online With Pros, Today

    Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

    Join & Write a Comment

    I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension ( This reminded me of questions tha…
    Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
    This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now