- ps命令
- watch命令
- at命令
- crontab命令(Linux定时任务)
- 文件目录操作命令
- 文件打包上传和下载
- 文件查找命令
- linux文件权限设置
- 磁盘存储相关
- 性能监控和优化命令
- 网络命令
- 其他命令
head命令
head 与 tail 就像它的名字一样的浅显易懂,它是用来显示开头或结尾某个数量的文字区块,head
用来显示文件的开头至标准输出中,而 tail
想当然尔就是看文件的结尾。
1.命令格式
head [参数]... [文件]...
2.命令功能
head
用来显示档案的开头至标准输出中,默认head
命令打印其相应文件的开头10
行。
3.命令参数
-q
隐藏文件名-v
显示文件名-c
<字节> 显示字节数-n
<行数> 显示的行数
4.使用实例
实例1:显示文件的前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]$
实例2:显示文件前n个字节
命令:
head -c 20 log.log
演示操作及输出:
[zyiz@localhost test]$ head -c 20 log.log this is line 1. this[zyiz@localhost test]$
实例3:文件的除了最后n个字节以外的内容
命令:
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]$
实例4:输出文件除了最后n行的全部内容
命令:
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]$
关注微信小程序
扫描二维码
程序员编程王