【问题标题】:Tail multiple files in CentOS在 CentOS 中跟踪多个文件
【发布时间】:2010-10-28 20:33:23
【问题描述】:

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

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

但是输出很不友好

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

我还有哪些选择?

【问题讨论】:

    标签: linux command-line centos tail


    【解决方案1】:

    Multitail 在 rpmforge 存储库中可用于 CentOS。要添加 rpmforge 存储库,请检查 the documentation on 3rd Party Repositories

    【讨论】:

    • 那个页面说:“RPMForge/RepoForge - 这是一个死项目。没有维护。不要使用。”
    【解决方案2】:

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

    链接是http://www.thegeekstuff.com/2009/09/multitail-to-view-tail-f-output-of-multiple-log-files-in-one-terminal/

    感谢拉梅什·纳塔拉詹

        $ 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】:

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

      【讨论】:

      • 你也可以在 GNU 的屏幕上做同样的事情。
      【解决方案4】:

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

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

      【讨论】:

        【解决方案5】:

        你可以使用watch命令,我用它同时跟踪两个文件:

        watch -n0 tail -n30 file1 file2

        【讨论】:

          【解决方案6】:

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

          我在我的 .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
          }
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2018-10-30
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2023-03-10
            • 2011-12-15
            • 2014-08-09
            • 1970-01-01
            相关资源
            最近更新 更多