本文翻译自:Remove the last line from a file in Bash
I have a file, foo.txt
, containing the following lines: 我有一个文件foo.txt
,包含以下行:
a
b
c
I want a simple command that results in the contents of foo.txt
being: 我想要一个简单的命令,导致foo.txt
的内容为:
a
b
#1楼
参考:https://stackoom.com/question/KU0o/从Bash中的文件中删除最后一行
#2楼
This is by far the fastest and simplest solution, especially on big files: 这是迄今为止最快,最简单的解决方案,尤其是在大文件上:
head -n -1 foo.txt > te