5.1 在标准输出设备上查看文件

cat

DOS用户使用type命令将文本文件的内容显示在屏幕上。Linux用户则可以使用cat命令,它做的事情与type命令一样。想在shell中查看文件吗?试试cat命令吧。

  1. $ cat Hopkins_-_The_Windhover.txt
  2. I caught this morning morning's minion, kingdom
  3. of daylight's dauphin, dapple-dawn-drawn Falcon, in his riding
  4. Of the rolling level underneath him steady air, and striding
  5. High there, how he rung upon the rein of a wimpling wing
  6. In his ecstasy! then off, off forth on swing,
  7. As a skate's heel sweeps smooth on a bow-bend: the hurl and gliding
  8. Rebuffed the big wind. My heart in hiding
  9. Stirred for a bird, -- the achieve of, the mastery of the thing!
  10. Brute beauty and valour and act, oh, air, pride, plume, here
  11. Buckle! AND the fire that breaks from thee then, a billion
  12. Times told lovelier, more dangerous, o my chevalier!
  13. No wonder of it: sheer plod makes plough down
  14. sillion
  15. Shine, and blue-bleak embers, ah my dear,
  16. Fall, gall themselves, and gash gold-vermilion.
  17. $

cat命令将文件打印到屏幕,然后直接返回到命令提示符。如果文件长度超出屏幕的范围,必须向上滚动才能看到刚才一闪而过的内容。

这正是使用cat命令的一个大问题:如果正在查看的文档很长,文件内容在屏幕上飞驰而过,这个过程可能要花不少时间,同时也很难阅读(你能想象这个命令会产生什么:cat Melville_-_Moby_ Dick.txt)。解决办法就是使用5.5节中介绍的less命令。