我尝试使用该选项拖尾两个文件:
tail -0f file1.log -0f file2.log
Run Code Online (Sandbox Code Playgroud)
在 Linux 中,我看到一个错误“tail : 一次只能处理一个文件”。
在 AIX 中,我看到错误为“无效选项”。
当我使用时,这很好用:
tail -f file1 -f file 2
Run Code Online (Sandbox Code Playgroud)
在 Linux 中,但不在 AIX 中。
我希望能够使用AIX/Linux-0f或-f在 AIX/Linux 中拖尾多个文件
multitail 在这些操作系统中的任何一个中都无法识别。
Sté*_*las 43
关于什么:
tail -f file1 & tail -f file2
Run Code Online (Sandbox Code Playgroud)
或者在每一行前面加上文件名:
tail -f file1 | sed 's/^/file1: /' &
tail -f file2 | sed 's/^/file2: /'
Run Code Online (Sandbox Code Playgroud)
要跟踪名称与模式匹配的所有文件,您可以tail -f使用以下zsh脚本实现(每秒连续读取文件):
#! /bin/zsh -
zmodload zsh/stat
zmodload zsh/zselect
zmodload zsh/system
set -o extendedglob
typeset -A tracked
typeset -F SECONDS=0
pattern=${1?}; shift
drain() {
while sysread -s 65536 -i $1 -o 1; do
continue
done
}
for ((t = 1; ; t++)); do
typeset -A still_there
still_there=()
for file in $^@/$~pattern(#q-.NoN); do
stat -H stat -- $file || continue
inode=$stat[device]:$stat[inode]
if
(($+tracked[$inode])) ||
{ exec {fd}< $file && tracked[$inode]=$fd; }
then
still_there[$inode]=
fi
done
for inode fd in ${(kv)tracked}; do
drain $fd
if ! (($+still_there[$inode])); then
exec {fd}<&-
unset "tracked[$inode]"
fi
done
((t <= SECONDS)) || zselect -t $((((t - SECONDS) * 100) | 0))
done
Run Code Online (Sandbox Code Playgroud)
然后例如,递归跟踪当前目录中的所有文本文件:
that-script '**/*.txt' .
Run Code Online (Sandbox Code Playgroud)
小智 18
在 OSX 和 Linux 中,使用
tail -f <file1> <file2>
Run Code Online (Sandbox Code Playgroud)
对我很有用。另一件好事是它具有以下输出:
==> /srv/www/my-app/shared/log/nginx.access.log <==
things from log 1
==> /srv/www/my-app/shared/log/nginx.error.log <==
things from log 2
==> /srv/www/my-app/shared/log/nginx.access.log <==
new things from log 1
Run Code Online (Sandbox Code Playgroud)
帮助您识别哪个输出来自哪个日志。
cuo*_*glm 13
tailGNU tail 版本扩展了多个文件。使用 AIX,您没有 GNU 尾巴,因此您不能这样做。你可以multitail改用。
您可以在 Linux 和 AIX 中安装multitail。
对于 AIX,您可以在此处下载软件包。
在 Linux 中,multitail通常在 repo 中,因此您可以使用发行版包管理器轻松安装它:
apt-get install multitailyum install multitail以下内容可以很好地在 std out 上输出内容
tail -f file1 & tail -f file2
Run Code Online (Sandbox Code Playgroud)
我想pipe输出到另一个进程。在上述情况下&,在后台运行之前制作零件,只有第二部分正在piped处理
所以我用
tail -f file1 file2 | process
Run Code Online (Sandbox Code Playgroud)
@Stéphane 你的回答是完美的,但只是提到我的用例,它有点扭曲。
我将提供一个代码片段,tmux它可以为您提供两个不同的窗口,您可以使用它同时跟踪两个文件:
tmux new-window -a -n Tail
tmux new-session -d -s Tail -n SSH0 -d
tmux selectp -t Tail
#This is tmux interactions with the user (colors of the tabs used, hot keys, etc.)
tmux bind-key -n M-Left previous-window -t WinSplit
tmux bind-key -n M-Right next-window -t WinSplit
tmux set-window-option -g monitor-activity on
tmux set -g visual-activity on
tmux set-window-option -g window-status-current-bg blue
tmux set-window-option -g window-status-fg red
tmux set -g pane-border-fg yellow
tmux set -g pane-active-border-bg red
tmux set -g message-fg yellow
tmux set -g message-bg red
tmux set -g message-attr bright
tmux set -g status-left "#[fg=red]#S"
#Names two seperate windows
tmux new-window -n tail1 -t Tail
tmux new-window -n tail2 -t Tail
#Now this will allow you to automatically run tail when this tmux script is run
tmux send-keys -t Tail:0 'tail -f file1.log' C-m
tmux send-keys -t Tail:1 'tail -f file2.log' C-m
Run Code Online (Sandbox Code Playgroud)
更新:使用screen还可以附加/分离多个会话,因此您tail也可以运行多次。我可以建议这样做:
screen -s Tail_Server1.log
接下来,您需要保持CTRL+A+D分离而不终止会话,然后下一步:
screen -s Tail_Server2.log
Run Code Online (Sandbox Code Playgroud)
两者都会单独运行两个screens,我会参考screen --help这样您可以将其调整为您希望两个屏幕在您的terminal.