打印文件的1~5行
[root@MIO-2 ~]# head -n 5 e.txt
打印文件的最后10行
[root@MIO-2 ~]# tail install.log Installing iwl4965-firmware-228.61.2.24-2.1.el6.noarch Installing rt61pci-firmware-1.2-7.el6.noarch Installing iwl3945-firmware-15.32.2.9-4.el6.noarch Installing ql2200-firmware-2.02.08-3.1.el6.noarch Installing rt73usb-firmware-1.8-7.el6.noarch Installing ipw2100-firmware-1.3-11.el6.noarch Installing ql23xx-firmware-3.03.27-3.1.el6.noarch Installing ipw2200-firmware-3.1-4.el6.noarch Installing rootfiles-8.1-6.1.el6.noarch
也可以用stdin中读取输入
[root@MIO-2 ~]# cat install.log | tail Installing iwl4965-firmware-228.61.2.24-2.1.el6.noarch Installing rt61pci-firmware-1.2-7.el6.noarch Installing iwl3945-firmware-15.32.2.9-4.el6.noarch ...
打印最后4行
[root@MIO-2 ~]# tail -n 4 install.log Installing ipw2100-firmware-1.3-11.el6.noarch Installing ql23xx-firmware-3.03.27-3.1.el6.noarch Installing ipw2200-firmware-3.1-4.el6.noarch Installing rootfiles-8.1-6.1.el6.noarch
打印330行之后的所有行
[root@MIO-2 ~]# tail -n +330 install.log Installing ql2400-firmware-5.08.00-1.el6.noarch Installing iwl5000-firmware-8.83.5.1_1-1.el6_1.1.noarch Installing ql2100-firmware-1.19.38-3.1.el6.noarch Installing ivtv-firmware-20080701-20.2.noarch Installing libertas-usb8388-firmware-5.110.22.p23-3.1.el6.noarch Installing xorg-x11-drv-ati-firmware-6.99.99-1.el6.noarch Installing ql2500-firmware-5.08.00-1.el6.noarch Installing atmel-firmware-1.3-7.el6.noarch Installing zd1211-firmware-1.4-4.el6.noarch Installing iwl4965-firmware-228.61.2.24-2.1.el6.noarch Installing rt61pci-firmware-1.2-7.el6.noarch Installing iwl3945-firmware-15.32.2.9-4.el6.noarch Installing ql2200-firmware-2.02.08-3.1.el6.noarch Installing rt73usb-firmware-1.8-7.el6.noarch Installing ipw2100-firmware-1.3-11.el6.noarch Installing ql23xx-firmware-3.03.27-3.1.el6.noarch Installing ipw2200-firmware-3.1-4.el6.noarch Installing rootfiles-8.1-6.1.el6.noarch
tail命令的一个重要用法是从一个不断更新的文件中读取数据,新增加的内容总是被添加到文件的尾部,因此当新内容被写入文件的时候,可以用tail将其显示出来
使用-f或—follow可以持续监视文件更新
tail -f filename
-s 加入一个间隔时间
每10秒更新一次
tail -f -s 10 filename