5.10 查看一个或多个文件的前几行内容
如果不想查看文件的前10行内容,可以使用-n
选项,后面跟上一个数字,比如5(或者用--lines=5
),让head
命令显示不同行数的内容。如果你指定两个或更多的文件,例如Chaucer的“Canterbury Tales”和Milton的“Paradise Lost”,结果将显示所有文件的前几行内容。
$ head -n 5 Canterbury_Tales.txt Paradise_Lost.txt
==> Canterbury_Tales.txt <==
Here bygynneth the Book of the Tales of Caunterbury
General Prologue
Whan that Aprill, with his shoures soote
==> Paradise_Lost.txt <==
Book I
Of Man's first disobedience, and the fruit
Of that forbidden tree whose mortal taste
Brought death into the World, and all our woe,
注意,这5行包括空白行和文本行。5行就是5行,不管这5行包含什么内容。