5.10 查看一个或多个文件的前几行内容

如果不想查看文件的前10行内容,可以使用-n选项,后面跟上一个数字,比如5(或者用--lines=5),让head命令显示不同行数的内容。如果你指定两个或更多的文件,例如Chaucer的“Canterbury Tales”和Milton的“Paradise Lost”,结果将显示所有文件的前几行内容。

  1. $ head -n 5 Canterbury_Tales.txt Paradise_Lost.txt
  2. ==> Canterbury_Tales.txt <==
  3. Here bygynneth the Book of the Tales of Caunterbury
  4. General Prologue
  5. Whan that Aprill, with his shoures soote
  6. ==> Paradise_Lost.txt <==
  7. Book I
  8. Of Man's first disobedience, and the fruit
  9. Of that forbidden tree whose mortal taste
  10. Brought death into the World, and all our woe,

注意,这5行包括空白行和文本行。5行就是5行,不管这5行包含什么内容。