【发布时间】:2011-04-16 01:54:21
【问题描述】:
是否可以使用简单的 shell 命令只保留一行的最后 10 行?
tail -n 10 test.log
提供正确的结果,但我不知道如何修改 test.log 本身。和
tail -n 10 test.log > test.log
没用。
【问题讨论】:
-
作为一个经验法则,永远不要同时使用一个文件作为输入和输出,你永远不知道它会如何结束。
-
好建议。我刚刚做了
tail -n 10 test.log > test.log,结果一无所获(一个空白文件)。