标签: tail

如何让 tail -f 用 vim 显示彩色输出?

在这个问题中,吉尔斯回答了

另一种可能性是tail -fEmacs shell 缓冲区中运行并使用 Emacs 的语法着色能力。

因为我是 vim 用户,所以我想用vim而不是emacs来做这件事。
请问VIM有这个功能吗?

command-line less colors vim tail

9
推荐指数
1
解决办法
2017
查看次数

这是 POSIX 指定的分组命令中的尾部行为吗?

使用tail与其他标准工具组合分组命令可以使一些强大的结构。例如,要获取文件的第一行和最后一行:

$ seq 10 > file
$ { head -n1; tail -n1; } <file
1
10
Run Code Online (Sandbox Code Playgroud)

当从管道组命令馈送文件的内容,tail不能产生输出,因为管是lseek的能够

$ seq 10 | { head -n1; tail -n1; }
1
Run Code Online (Sandbox Code Playgroud)

现在,当内容足够大时,tail工作:

$ seq 10000 | { head -n1; tail -n1; }
1
10000
Run Code Online (Sandbox Code Playgroud)

那是因为在第一次lseek失败后,tail知道它不是一个可查找的文件描述符,并且因为管道的内容还没有被全部读取,它开始读取内容直到结束。

作为用户的观点,我希望无论输入内容大小如何,行为都应该是一致的。我查看了 POSIX taillseek文档并没有找到任何描述。

这种行为是否由 POSIX 指定?如果没有,我怎样才能使结果始终一致?


我已经用 GNU tail 和 FreeBSD tail 进行了测试,两者都具有相同的行为。

pipe tail posix

9
推荐指数
1
解决办法
272
查看次数

通过 sshfs 对文本文件执行 tail -f 不起作用。为什么?

我成功地在远程 ssh 主机上安装了一个本地文件夹。

我现在想做一个,tail -500f my_text_file但效果不佳。尽管它确实打开了尾部并向我显示了文件内容,但该-f部分绝对不起作用。这一定与sshfs. 当我进行常规 ssh 连接时,它运行得非常好。

有关如何解决此问题的任何指示?我正在使用 sshfs 版本,sudo apt install sshfs在 Ubuntu 中执行时获得。

tail sshfs

9
推荐指数
2
解决办法
702
查看次数

是否可以在开头截断文件(就地,相同的索引节点)?

可以删除 a 的尾随字节,file而无需写入新文件 ( > newfile) 并将其移回 ( mv newfile file)。这是通过以下方式完成的truncate

truncate -s -1 file
Run Code Online (Sandbox Code Playgroud)

可以删除前导字节,但通过移动它(这会改变 inode)(对于某些版本的 tail):

tail -c +1 file > newfile ; mv newfile file
Run Code Online (Sandbox Code Playgroud)

那么:如何在不移动文件的情况下做到这一点?
理想情况下,就像截断一样,即使对于非常大的文件也只需要更改几个字节。

注意:sed -i将更改文件索引节点,因此,即使它可能有用,也不是这个问题的答案(IMO)。

shell tail files truncate

9
推荐指数
2
解决办法
6110
查看次数

刷新“tail -f”缓冲区?

我正在使用以下语句(简化版):

tail -f -c+1 <filename>
Run Code Online (Sandbox Code Playgroud)

为了将文件通过管道传输到进程。

不过,我发现最后有许多行没有通过管道连接。

一个具体的例子是管道一个 mysql 文件,并在到达结束时停止:

tail -f -c+1 mysqdump.sql | sed '/^-- Dump completed/ q0'
Run Code Online (Sandbox Code Playgroud)

这不起作用 - 转储的最后一行-- Dump completed [...]没有通过管道传输到 sed。

我的猜测是tail -f,在这种情况下,缓冲区仅在已满时才刷新。

有谁知道我该如何解决这个问题?

==================

我找到了原因 - 描述不完整(并且代码没有表现出行为)。

从压缩 (lzma) 文件进行管道传输时会出现问题:

tail -f -c+1 <filename.lzma> | lzma -d | sed '/^-- Dump completed/ q0'
Run Code Online (Sandbox Code Playgroud)

很可能tail没有发送最后一个压缩块,因为它没有检测到任何新行,因为输入是二进制的。

pipe tail

8
推荐指数
1
解决办法
1万
查看次数

如何在最新的日志文件更改日期时拖尾日志文件并继续拖尾?

我正在使用 RHEL 4。

tail -F file_name*.log当时间翻转到 0000 时,法线不会更新。

这是我迄今为止在搜索网络时所尝试的,两者都尝试使用嵌套tail

tail -F $(ls -tr file_name*.log | tail -n 1)

tail -F $(fine . -maxdepth 1 -type f -printf "%T@ %p\n" | sort -n | tail n 1 | cut -d' ' -f 2-)

这些都没有翻转到新文件。tail -F file_name*.log在我的小型测试用例中,旧的工作正常(而上面的 2 个没有),但是当我拖尾一个真实的日志文件时它不起作用。

logs tail

8
推荐指数
2
解决办法
6万
查看次数

使用 `less` 或 `tail -f` 滚动输出,同时保持标题可见

我试图滚动浏览一些这样格式化的数据-

       NFI T[PSEC]   T[K]  EKIN(PSI)    E(RHO)       ECONS    ANNEE  ANNER
!>     1   0.00012     0   0.45873     16.26904     16.72777 0.30000 0.00000
!>     2   0.00024     0   1.53365     13.91887     15.45251 0.29100 0.00000
!>     3   0.00036     0   2.57649     10.44460     13.02109 0.28227 0.00000
!>     4   0.00048     0   3.27986      6.47437      9.75423 0.27380 0.00000
!>     5   0.00060     0   3.76512      2.20938      5.97450 0.26559 0.00000
!>     6   0.00073     0   4.07033     -2.21948      1.85085 0.25762 0.00000
!>     7   0.00085     0   4.01375     -6.33776     -2.32402 0.24989 0.00000
!>     8   0.00097     0   3.47760     -9.51439     -6.03679 0.24239 …
Run Code Online (Sandbox Code Playgroud)

less bash tail

8
推荐指数
0
解决办法
303
查看次数

如何按时间拖尾日志文件?

说我的日志文件(log.txt)是这样的

2014-01-01 22:30:30 something happened....
2014-01-01 22:30:31 something happened....
2014-01-01 22:30:41 something happened....
Run Code Online (Sandbox Code Playgroud)

我想拖尾这个文件以显示最后一小时的日志,并继续拖尾..

IE

tail <some magic to specify last 1 hour> -f log.txt
Run Code Online (Sandbox Code Playgroud)

然后输出是

2014-01-01 21:30:41 something happened....
...
2014-01-01 22:30:30 something happened....
2014-01-01 22:30:31 something happened....
2014-01-01 22:30:41 something happened....
Run Code Online (Sandbox Code Playgroud)

有没有工具可以做到这一点?

linux command-line bash shell-script tail

8
推荐指数
1
解决办法
6万
查看次数

没有文件名和标题的目录中的尾文件

以下脚本可用于 cat 目录中没有标题的所有文件,但会打印文件名。没有文件名我怎么能猫。

tail -n +2 * >> Compile
Run Code Online (Sandbox Code Playgroud)

tail

8
推荐指数
2
解决办法
5415
查看次数

读取命名管道:tail 还是 cat?

我使用了一个文件描述符

mkfifo fifo
Run Code Online (Sandbox Code Playgroud)

一旦有东西写入这个管道,我想立即重用它。我应该使用

tail -f fifo
Run Code Online (Sandbox Code Playgroud)

或者

while true; do cat fifo; done
Run Code Online (Sandbox Code Playgroud)

?

他们似乎做同样的事情,我无法衡量性能差异。但是,当系统不支持inotify(例如Busybox)时,前者需要

tail -f -s 0 fifo
Run Code Online (Sandbox Code Playgroud)

但这会以 100% 的使用率消耗 CPU(测试一下:mkfifo fifo && busybox tail -f -s 0 fifo & echo hi>fifo/ 用fg 1和取消CtrlC)。那么 while-true-cat 是更可靠的解决方案吗?

pipe tail cat fifo

8
推荐指数
1
解决办法
4496
查看次数

标签 统计

tail ×10

pipe ×3

bash ×2

command-line ×2

less ×2

cat ×1

colors ×1

fifo ×1

files ×1

linux ×1

logs ×1

posix ×1

shell ×1

shell-script ×1

sshfs ×1

truncate ×1

vim ×1