Tail multiple files in CentOS

 ̄綄美尐妖づ 提交于 2019-12-10 13:43:52

问题


I want to tail multiple files (and follow them) in CentOS, I've tried this:

tail -f file1 file2 file3

but the output is very unfriendly

I've also had a look at multitail but can't find a CentOS version.

What other choices do I have?


回答1:


Multitail is available for CentOS in rpmforge repos. To add rpmforge repository check the documentation on 3rd Party Repositories.




回答2:


I found the solution described here work well on centos:

The link is http://www.thegeekstuff.com/2009/09/multitail-to-view-tail-f-output-of-multiple-log-files-in-one-terminal/

Thanks to Ramesh Natarajan

    $ 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



回答3:


You could simulate multitail by opening multiple instances of tail -f in Emacs subwindows.




回答4:


I usually just open another xterm and run a separate 'tail -f' there.

Otherwise if I'm using the 'screen' tool, I'll set up separate 'tail -f' commands there. I don't like that as much because it takes a few keystrokes to enable scrolling in screen before using the Page Up and Page Down keys. I prefer to just use xterm's scroll bar.




回答5:


You can use the watch command, i use it to tail two files at the same time:

watch -n0 tail -n30 file1 file2




回答6:


A better answer to an old question...

I create a shell function in my .bashrc (obviously assumes you're using bash as your shell) and use tmux. You can probably complicate this a whole lot and do it without the tempfile, but the quoting is just ugly if you're trying to ensure that files with spaces or other weird characters in the name still work.

multitail ()
{
    cmdfile=`mktemp`

    echo "new-session -d \"tail -f '$1'\"" >$cmdfile
    shift

    for file in "$@"
    do
        echo "split-window -d \"tail -f '$file'\"" >>$cmdfile
    done

    echo "select-layout even-vertical" >>$cmdfile
    tmux source-file $cmdfile \; attach && rm -f $cmdfile
}


来源:https://stackoverflow.com/questions/908548/tail-multiple-files-in-centos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!