head 与 tail 就像它的名字一样的浅显易懂,它是用来显示开头或结尾某个数量的文字区块,head
用来显示文件的开头至标准输出中,而 tail
想当然尔就是看文件的结尾。
head [参数]... [文件]...
head
用来显示档案的开头至标准输出中,默认head
命令打印其相应文件的开头10
行。
-q
隐藏文件名-v
显示文件名-c
<字节> 显示字节数-n
<行数> 显示的行数命令:
head -n 5 log.log
演示操作及输出:
[zyiz@localhost test]$ cat log.log this is line 1. this is line 2. this is line 3. this is line 4. this is line5. this is line 6. this is line 7. this is line 8. this is line 9. this is line 10. this is line 11. this is line 12. this is line 13. this is line 14. this is line 15. this is line 16. this is line 17. this is line 18. this is line 19. this is line 20. this is line 21. this is line 22. -----------------end [zyiz@localhost test]$ head -n 5 log.log this is line 1. this is line 2. this is line 3. this is line 4. [zyiz@localhost test]$
命令:
head -c 20 log.log
演示操作及输出:
[zyiz@localhost test]$ head -c 20 log.log this is line 1. this[zyiz@localhost test]$
命令:
head -c -32 log.log
演示操作及输出:
[zyiz@localhost test]$ head -c -32 log.log this is line 1. this is line 2. this is line 3. this is line 4. this is line5. this is line 6. this is line 7. this is line 8. this is line 9. this is line 10. this is line 11. this is line 12. this is line 13. this is line 14. this is line 15. this is line 16. this is line 17. this is line 18. this is line 19. this is line 20. this is line 21. [zyiz@localhost test]$
命令:
head -n -6 log.log ```shell 演示操作及输出: ```shell [zyiz@localhost test]$ head -n -6 log.log this is line 1. this is line 2. this is line 3. this is line 4. this is line5. this is line 6. this is line 7. this is line 8. this is line 9. this is line 10. this is line 11. this is line 12. this is line 13. this is line 14. this is line 15. this is line 16. this is line 17. this is line 18. [zyiz@localhost test]$