除了最后 2 行,我怎样才能 cat/print 一个文件?

Pro*_*ken 10 unix bash awk sed sh

如何使用标准或 GNU shell 工具获取文本文件的内容,除了最后(例如)2 行?(bash、tail、cat 等等。)

Tho*_*hor 20

使用 coreutils 中的 head 命令:

head -n -2
Run Code Online (Sandbox Code Playgroud)

查看info head更多。


iiS*_*our 5

你只是想要。

head -n-2 file
Run Code Online (Sandbox Code Playgroud)

阅读man head更多信息。