Use the ‘head’ Command in Linux

by | Sep 22, 2023 | Etcetera | 0 comments

The head command stands as a simple however tricky software for report manipulation. It’s necessarily used to turn the main few lines of a report, allowing consumers to briefly glance at the start of a report without having to open the entire report. This can be extraordinarily handy for previewing massive information or scripts.

Similar to the head command, the tail command is often used in conjunction, allowing consumers to view the highest of a report. Together, the ones directions provide a whole view of a report’s content material subject material. The head command is particularly useful for system administrators, wisdom analysts, and developers who want to sift by means of log information or massive datasets. It can be paired with other directions like grep to filter specific wisdom

Use head

1. head

Explanation: Presentations the main 10 lines of a report.

Example: head report.txt

Output:

Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10

The command displays the main 10 lines of the report named report.txt.

2. head -n 5

Explanation: Presentations the main 5 lines of a report.

Example: head -n 5 report.txt

Output:

Line 1
Line 2
Line 3
Line 4
Line 5

The command displays the main 5 lines of the report named report.txt.

3. head -c 20

Explanation: Presentations the main 20 bytes of a report.

See also  The way to Create Template Units The usage of Divi’s Theme Builder Library

Example: head -c 20 report.txt

Output:

Line 1
Line 2
Li

The command displays the main 20 bytes of the report named report.txt.

4. head -q

Explanation: Presentations the main 10 lines of multiple information without headers.

Example: head -q file1.txt file2.txt

Output:

Line 1 of file1
Line 2 of file1
...
Line 1 of file2
Line 2 of file2
...

The command displays the main 10 lines of each and every file1.txt and file2.txt without printing the report names as headers.

5. head -v

Explanation: Presentations the main 10 lines of multiple information with headers.

Example: head -v file1.txt file2.txt

Output:

==> file1.txt  file2.txt <==
Line 1 of file2
...

The command displays the main 10 lines of each and every file1.txt and file2.txt, along side the report names as headers.

6. head -n -5

Explanation: Presentations all on the other hand the ultimate 5 lines of a report.

Example: head -n -5 report.txt

Output:

Line 1
...
Line (n-5)

The command displays the entire lines of report.txt except the ultimate 5.

7. tail report.txt | head -n 3

Explanation: Presentations the main 3 lines of the ultimate 10 lines of a report.

Example: tail report.txt | head -n 3

Output:

Line (n-9)
Line (n-8)
Line (n-7)

The command first retrieves the ultimate 10 lines of report.txt the use of tail, then pipes that output to head, showing the main 3 lines of those ultimate 10.

8. head -n 5 file1.txt file2.txt

Explanation: Presentations the main 5 lines of multiple information.

Example: head -n 5 file1.txt file2.txt

Output:

==> file1.txt  file2.txt <==
Line 1 of file2
...

The command displays the main 5 lines of each and every file1.txt and file2.txt, along side the report names as headers.

Additional Linux directions:
List Operations rmdir · cd · pwd
Document Operations cat · cp · dd · much less · ls · mkdir · mv · tail · tar · zip
Document Device Operations chown · mkfs
Networking ping · curl · wget · iptables
Search and Text Processing to find · grep · sed · whatis
Device Wisdom and Keep watch over env · historical past · best · who
Particular person and Session Keep watch over display screen · su · sudo

The post Use the ‘head’ Command in Linux gave the impression first on Hongkiat.

See also  8 Tricks to Simplify Your Paintings lifestyles

WordPress Website Development

Supply: https://www.hongkiat.com/blog/linux-command-head/

[ continue ]

WordPress Maintenance Plans | WordPress Hosting

read more

0 Comments

Submit a Comment

DON'T LET YOUR WEBSITE GET DESTROYED BY HACKERS!

Get your FREE copy of our Cyber Security for WordPress® whitepaper.

You'll also get exclusive access to discounts that are only found at the bottom of our WP CyberSec whitepaper.

You have Successfully Subscribed!