Linux head Command

Linux 命令大全Linux Command Reference

The head command is used to view the content at the beginning of a file. There is a commonly used parameter-nused to display the number of lines, with a default of 10, i.e., it displays 10 lines of content.

If you need to view the tail part of a file, use the commandtail。

Command format:

head [参数] [文件]  

Parameters:

  • -q Hide file name
  • -v Display file name
  • -c<number> Display the number of bytes.
  • -n<number> Display the number of lines.

Examples

To display the first 10 lines of the example_notes.log file, enter the following command (with default parameters-n 10):

head example_notes.log

The above command is equivalent to:

head -n 10 runoon_notes.log

To display the first 5 lines of the notes.log file, enter the following command:

head -n 5 example_notes.log

Display the first 20 bytes of the file:

head -c 20 example_notes.log

Linux 命令大全Linux Command Reference

Other Extensions