您可以使用 head
head -n-7 file
Run Code Online (Sandbox Code Playgroud)
来自手册页:
-n, --lines=[-]K
print the first K lines instead of the first 10;
with the leading '-', print all but the last K lines of each file
Run Code Online (Sandbox Code Playgroud)
喜欢:
kent$ seq 10|head -n-7
1
2
3
Run Code Online (Sandbox Code Playgroud)