美文网首页
每日一个linux命令13-head

每日一个linux命令13-head

作者: 1519f8ccc7b0 | 来源:发表于2017-04-17 20:43 被阅读0次

    1. 命令解析

    命令用途

    显示文件的前N行至屏幕,默认输出文件的前10行;

    命令格式

    head [OPTION]... [FILE]...

    命令参数

    -c, --bytes=[-]K print the first K bytes of each file;
    with the leading '-', print all but the last
    K bytes of each file
    -n, --lines=[-]K print the first K lines instead of the first 10;
    with the leading '-', print all but the last
    K lines of each file
    -q, --quiet, --silent never print headers giving file names
    -v, --verbose always print headers giving file names

    2. 示例

    2.1 显示文件的前10行

    [root@test headTest]# head hisotry.log 
        1  cd /root
        2  ls
        3  mkdir test
        4  cd test
        5  mk catTest
        6  mkdir catTest
        7  cd catTest/
        8  ls
        9  cat --help
       10  cat > f1
    

    2.2 指定显示的行数 -n

    [root@test headTest]# head -n5 hisotry.log 
        1  cd /root
        2  ls
        3  mkdir test
        4  cd test
        5  mk catTest
    

    2.3 显示文件名 -v

    [root@test headTest]# head -v hisotry.log 
    ==> hisotry.log <==
        1  cd /root
        2  ls
        3  mkdir test
        4  cd test
        5  mk catTest
        6  mkdir catTest
        7  cd catTest/
        8  ls
        9  cat --help
       10  cat > f1
    

    2.4 显示文件的除去最后212行的全部内容 -n负数

    [root@test headTest]# head -n -212 hisotry.log 
        1  cd /root
        2  ls
        3  mkdir test
        4  cd test
        5  mk catTest
        6  mkdir catTest
        7  cd catTest/
        8  ls
        9  cat --help
       10  cat > f1
    
    

    2.5 按字节数显示 -c

    [root@test headTest]# head -c 50 hisotry.log 
        1  cd /root
        2  ls
        3  mkdir test
        4 [root@test headTest]# 
    

    相关文章

      网友评论

          本文标题:每日一个linux命令13-head

          本文链接:https://www.haomeiwen.com/subject/fghxzttx.html