tail、tailf、head命令

tail命令

查看文件的末尾10行

[root@localhost test]# vim log_file
line1
line2
line3
line4
line5
Hello World - line 6
line7
line8
line9
line10
line11
Hello again - line 12 
line13 
line14 
line15 
Sweet - line16 
line17 
line18 
line19 
Last line - line20 

使用tail命令查看

[root@localhost test]# tail log_file |cat -n
     1    line11
     2    Hello again - line 12 
     3    line13 
     4    line14 
     5    line15 
     6    Sweet - line16 
     7    line17 
     8    line18 
     9    line19 
    10    Last line - line20 

-n 查看指定行数

[root@localhost test]# tail -n 3 log_file |cat -n
     1    line18 
     2    line19 
     3    Last line - line20 

[root@localhost test]# tail -3 log_file |cat -n
     1    line18 
     2    line19 
     3    Last line - line20 

-f 实时查看文件的变化

[root@localhost test]# tail -f log_file 
line11
Hello again - line 12 
line13 
line14 
line15 
Sweet - line16 
line17 
line18 
line19 
Last line - line20 
...

tailf命令 相当于tail -f 

[root@localhost test]# tailf log_file 
line11
Hello again - line 12 
line13 
line14 
line15 
Sweet - line16 
line17 
line18 
line19 
Last line - line20 

head命令

查看文件前10行内容,参数基本和tail相同

 

tail、tailf、head命令

上一篇:题解 P4093 [HEOI2016/TJOI2016]序列


下一篇:html5学习之第一步:认识标签,了解布局