Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to use head Command in linux

Shulou Source: shulou.com Published: 2022-06-01 12:16:41 10月12日 Update

This article mainly explains the "use of head commands in linux", the content of the explanation is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "the use of head commands in linux" bar!

1. Command format:

Head [parameters]... [file].

2. Command function:

Head is used to display the beginning of an archive to standard output, and the default head command prints the first 10 lines of its corresponding file.

3. Command parameters:

-Q hide file name

-v displays the file name

-c displays the number of bytes

Number of rows displayed by-n

4. Use an example:

Example 1: display the first n lines of the file

Command:

Head-n 5 log2014.log

Output:

The code is as follows:

[root@localhost test] # cat log2014.log

2014-01

2014-02

2014-03

2014-04

2014-05

2014-06

2014-07

2014-08

2014-09

2014-10

2014-11

2014-12

= =

[root@localhost test] # head-n 5 log2014.log

2014-01

2014-02

2014-03

2014-04

2014-05 [root@localhost test] #

Example 2: display the first n bytes of the file

Command:

Head-c 20 log2014.log

Output:

The code is as follows:

[root@localhost test] # head-c 20 log2014.log

2014-01

2014-02

2014

[root@localhost test] #

Example 3: the contents of the file except the last n bytes

Command:

Head-c-32 log2014.log

Output:

The code is as follows:

[root@localhost test] # head-c-32 log2014.log

2014-01

2014-02

2014-03

2014-04

2014-05

2014-06

2014-07

2014-08

2014-09

2014-10

2014-11

2014-12 [root@localhost test] #

Example 4: all the contents of the output file except the last n lines

Command:

Head-n-6 log2014.log

Output:

The code is as follows:

[root@localhost test] # head-n-6 log2014.log

2014-01

2014-02

2014-03

2014-04

2014-05

2014-06

2014-07 [root@localhost test] #

Thank you for your reading, these are the contents of "the use of head commands in linux". After the study of this article, I believe you have a deeper understanding of the use of head commands in linux, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Commands files output examples usage methods code content bytes learning parameters beginning file name function that is ideas situations articles more standards Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi OPPO Reno Docker Microsoft Shulou Information