The head
command stands as a easy but tough instrument for record manipulation. It’s essentially used to show the primary few strains of a record, permitting customers to temporarily look originally of a file while not having to open all of the record. This will also be extremely to hand for previewing huge recordsdata or scripts.
Very similar to the head
command, the tail
command is incessantly utilized in conjunction, permitting customers to view the top of a record. In combination, those instructions supply a complete view of a record’s content material. The head
command is especially helpful for gadget directors, knowledge analysts, and builders who wish to sift via log recordsdata or huge datasets. It may also be paired with different instructions like grep
to filter out particular knowledge
Use head
1. head
Clarification: Shows the primary 10 strains of a record.
Instance: head record.txt
Output:
Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 Line 10
The command shows the primary 10 strains of the record named record.txt
.
2. head -n 5
Clarification: Shows the primary 5 strains of a record.
Instance: head -n 5 record.txt
Output:
Line 1 Line 2 Line 3 Line 4 Line 5
The command shows the primary 5 strains of the record named record.txt
.
3. head -c 20
Clarification: Shows the primary 20 bytes of a record.
Instance: head -c 20 record.txt
Output:
Line 1 Line 2 Li
The command shows the primary 20 bytes of the record named record.txt
.
4. head -q
Clarification: Shows the primary 10 strains of more than one recordsdata with out headers.
Instance: 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 shows the primary 10 strains of each file1.txt
and file2.txt
with out printing the record names as headers.
5. head -v
Clarification: Shows the primary 10 strains of more than one recordsdata with headers.
Instance: head -v file1.txt file2.txt
Output:
==> file1.txt file2.txt <== Line 1 of file2 ...
The command shows the primary 10 strains of each file1.txt
and file2.txt
, together with the record names as headers.
6. head -n -5
Clarification: Shows all however the closing 5 strains of a record.
Instance: head -n -5 record.txt
Output:
Line 1 ... Line (n-5)
The command shows all of the strains of record.txt
apart from the closing 5.
7. tail record.txt | head -n 3
Clarification: Shows the primary 3 strains of the closing 10 strains of a record.
Instance: tail record.txt | head -n 3
Output:
Line (n-9) Line (n-8) Line (n-7)
The command first retrieves the closing 10 strains of record.txt
the usage of tail, then pipes that output to go, exhibiting the primary 3 strains of the ones closing 10.
8. head -n 5 file1.txt file2.txt
Clarification: Shows the primary 5 strains of more than one recordsdata.
Instance: head -n 5 file1.txt file2.txt
Output:
==> file1.txt file2.txt <== Line 1 of file2 ...
The command shows the primary 5 strains of each file1.txt
and file2.txt
, together with the record names as headers.
Extra Linux instructions:
Listing Operations | rmdir · cd · pwd |
Record Operations | cat · cp · dd · much less · ls · mkdir · mv · tail · tar · zip |
Record Machine Operations | chown · mkfs |
Networking | ping · curl · wget · iptables |
Seek and Textual content Processing | to find · grep · sed · whatis |
Machine Knowledge and Control | env · historical past · best · who |
Person and Consultation Control | display screen · su · sudo |
The put up Use the ‘head’ Command in Linux seemed first on Hongkiat.
WordPress Website Development Source: https://www.hongkiat.com/blog/linux-command-head/