Get the App
SLTechnology News&Howtos  ›  Servers  › 

Use the head command of linux to display the beginning of the file

Shulou Source: shulou.com Published: 2022-06-02 18:59:34 09月22日 Update

Editor to share with you the use of linux's head command to display the beginning of the file, I hope you will learn a lot after reading this article, let's discuss it together!

The head command fetches the contents of the file in behavior units, and prints the first 10 lines by default without parameters.

Syntax format: head [parameters] [file]

Common parameters:

-n is followed by a number, which means how many lines to display-c specifies the number of characters to display high-quality content-v always displays the header information of the file name-Q does not display the header information of the file name

Reference example

Display the contents of the first 3 lines of the file:

[root@linuxcool] # head-n 3 install.logInstalling libgcc-4.4.7-23.el6.x86_64warning: libgcc-4.4.7-23.el6.x86_64: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEYInstalling setup-2.8.14-23.el6.noarch

Displays the file name information and the first two lines of the file:

[root@linuxcool] # head-v-n 2 test.txt = = > test.txt

Tags: File content command information parameter file name beginning character article representative unit header finished instance commonly used meaning number more format knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Apple MySQL macOS Shulou Information