• Linux命令(93)之head


    linux命令之head

    1.head介绍

    linux命令head用来查看文件的前N行内容;默认head查看前10行

    2.head用法

    head [参数] 文件

    head常用参数
    参数说明
    -n从头显示N行,默认显示10行,可以不写
    -q隐藏文件名,在查看两个及以上文件名的情况下有效
    -v显示文件名
    -c从头显示N字节的内容

    3.实例

    3.1.显示文件的前5行

    命令:

    head -n 5 a.txt

    OR

    head -5 a.txt

    1. [root@centos79-3 ~]# head -n 5 a.txt
    2. 1
    3. 2
    4. 3
    5. 4
    6. 5
    7. [root@centos79-3 ~]# head -5 a.txt
    8. 1
    9. 2
    10. 3
    11. 4
    12. 5
    13. [root@centos79-3 ~]#

    3.2.显示文件的前5个字节的内容

    命令:

    head -c 5 a.txt

    OR

    head -c5 a.txt

    1. [root@centos79-3 ~]# head -c 5 a.txt
    2. 1
    3. 2
    4. 3[root@centos79-3 ~]# head -c5 a.txt
    5. 1
    6. 2
    7. 3[root@centos79-3 ~]#

    3.3.显示输出内容的文件名

    命令:

    head -v a.txt

    1. [root@centos79-3 ~]# head a.txt
    2. 1
    3. 2
    4. 3
    5. 4
    6. 5
    7. 6
    8. 7
    9. 8
    10. 9
    11. 10
    12. [root@centos79-3 ~]# head -v a.txt
    13. ==> a.txt <==
    14. 1
    15. 2
    16. 3
    17. 4
    18. 5
    19. 6
    20. 7
    21. 8
    22. 9
    23. 10
    24. [root@centos79-3 ~]#

    3.4.显示除文件后两行的剩余内容

    命令:

    head -n -2 a.txt

    1. [root@centos79-3 ~]# cat a.txt
    2. 1
    3. 2
    4. 3
    5. 4
    6. 5
    7. 6
    8. 7
    9. 8
    10. 9
    11. 10
    12. 11
    13. 12
    14. [root@centos79-3 ~]# head -n -2 a.txt
    15. 1
    16. 2
    17. 3
    18. 4
    19. 5
    20. 6
    21. 7
    22. 8
    23. 9
    24. 10
    25. [root@centos79-3 ~]#

    3.5.显示除文件后两个字符的剩余内容

    命令:

    head -c -2 a.txt

    1. [root@centos79-3 ~]# cat a.txt
    2. 1
    3. 2
    4. 3
    5. 4
    6. 5
    7. 6
    8. 7
    9. 8
    10. 9
    11. 10
    12. 11
    13. 12
    14. [root@centos79-3 ~]# head -c -2 a.txt
    15. 1
    16. 2
    17. 3
    18. 4
    19. 5
    20. 6
    21. 7
    22. 8
    23. 9
    24. 10
    25. 11
    26. 1[root@centos79-3 ~]#

    3.6.显示内容时隐藏文件的名称

    命令:

    head -n 5 -q a.txt b.txt

    1. [root@centos79-3 ~]# head -n 5 a.txt b.txt
    2. ==> a.txt <==
    3. 1
    4. 2
    5. 3
    6. 4
    7. 5
    8. ==> b.txt <==
    9. 1
    10. 2
    11. 3
    12. 4
    13. 5
    14. [root@centos79-3 ~]# head -n 5 -q a.txt b.txt
    15. 1
    16. 2
    17. 3
    18. 4
    19. 5
    20. 1
    21. 2
    22. 3
    23. 4
    24. 5
    25. [root@centos79-3 ~]#

  • 相关阅读:
    docker部署tomcat
    9种js数组去重方法都有哪些?
    PMP考试提分必刷题
    CentOS7 安装 kafka
    T1024:保留3位小数的浮点数(信息学一本通C++)
    【点云压缩】点云概述:点云的分类与处理 点云来源
    C#数组基础
    万字解析设计模式之 装饰者模式
    webStorm内存溢出问题
    SpringCloud与Dubbo的区别
  • 原文地址:https://blog.csdn.net/z19861216/article/details/132982881