[Linux命令]tail -f 报错:file truncated
1 报错内容
首先:终端1 输入并回车
tail -f /tmp/test.txt
其次:终端2 输入并回车
echo "this is the first sentence." > /tmp/test.txt
最后,终端1 报错
tail: /tmp/test.txt: file truncated
2 解决方法
方法1 > 改为 >>
echo "this is the first sentence." >> /tmp/test.txt
方法2 -f改为-F
tail -F /tmp/test.txt
PS: Ctrl+C 退出实时监控(终端1)
3 解释
> 覆盖: 原文先被清空,再写入新内容(tail 原本监控的文件被截断了)
>> 追加:在原文后新增,不影响原文
抛个问题:
echo "this is the first sentence." > /tmp/test.txt
tail -F /tmp/test.txt
这种情况为何成功输出。。。待更