一天一个 Linux 命令(14):head 命令

一、简介

head 就像它的名字一样的浅显易懂,它是用来查看文件的开头部分的内容

二、格式说明

head [OPTION]... [FILE]...
head [参数]... [文件]...

Usage: head [OPTION]... [FILE]...
Print the first 10 lines of each FILE to standard output.
With more than one FILE, precede each with a header giving the file name.
With no FILE, or when FILE is -, read standard input.

Mandatory arguments to long options are mandatory for short options too.
  -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
      --help     display this help and exit
      --version  output version information and exit


三、选项说明

-q 隐藏文件名
-v 显示文件名
-c<数目> 显示的字节数。
-n<行数> 显示的行数。

四、命令功能

head 用来查看文件的开头部分的内容,默认head命令打印其相应文件的开头10行。

五、常见用法

1.显示 test.log 文件的开头 10 行

head test.log

2.显示 test.log 文件的开头 5 行

head -n 5 test.log

3.显示test.log 文件前 50 个字节

head -c 50 test.log

4.文件的除了最后 50 个字节以外的内容

head -c -50 test.log

5.输出文件除了最后 10 行的全部内容

head -n -10 test.log

 

原文地址:https://www.cnblogs.com/joshua317/p/15305872.html