CentOS 中尾部多个文件

发布于 2024-07-22 11:54:24 字数 177 浏览 11 评论 0原文

我想在 CentOS 中跟踪多个文件(并跟踪它们),我已经尝试过:

tail -f 文件1 文件2 文件3

但输出非常不友好

我也看过 multitail 但找不到 CentOS 版本。

我还有什么其他选择?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

著墨染雨君画夕 2024-07-29 11:54:24

Multitail 可在 rpmforge 存储库中用于 CentOS。 要添加 rpmforge 存储库,请检查有关第 3 方存储库的文档

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

雨巷深深 2024-07-29 11:54:24

我发现这里描述的解决方案在centos上运行良好:

链接是http://www.thegeekstuff.com/2009/09/multitail-to-view-tail-f-output-of-multiple-log-files-在一个终端/

感谢 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

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
落在眉间の轻吻 2024-07-29 11:54:24

您可以通过在 Emacs 子窗口中打开 tail -f 的多个实例来模拟多尾。

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

慈悲佛祖 2024-07-29 11:54:24

我通常只是打开另一个 xterm 并在那里运行单独的“tail -f”。

否则,如果我使用“screen”工具,我将在那里设置单独的“tail -f”命令。 我不太喜欢这样,因为在使用 Page Up 和 Page Down 键之前需要敲击几次按键才能在屏幕中滚动。 我更喜欢只使用 xterm 的滚动条。

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.

风透绣罗衣 2024-07-29 11:54:24

您可以使用 watch 命令,我用它同时尾部两个文件:

watch -n0 tail -n30 file1 file2

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

watch -n0 tail -n30 file1 file2

英雄似剑 2024-07-29 11:54:24

对一个老问题的更好答案...

我在 .bashrc 中创建了一个 shell 函数(显然假设您使用 bash 作为 shell)并使用 tmux。 您可能可以使这一切变得更加复杂,并且在没有临时文件的情况下完成它,但是如果您试图确保名称中带有空格或其他奇怪字符的文件仍然有效,那么引用就很难看。

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
}

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
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文