To view the beginning of files in a terminal, you can use the head command. Here’s how to do it:
Basic Usage of head:
-
View the First 10 Lines (Default):
By default,headdisplays the first 10 lines of a file.head filename.txt -
View a Specific Number of Lines:
You can specify the number of lines to display using the-noption.head -n 5 filename.txtThis command will show the first 5 lines of
filename.txt. -
View a Specific Number of Bytes:
You can also view a specific number of bytes using the-coption.head -c 50 filename.txtThis command will display the first 50 bytes of
filename.txt.
Example:
To view the first 10 lines of a file named example.txt, you would run:
head example.txt
Additional Options:
- You can combine
headwith other commands using pipes to filter or process data further. - For example, to view the first 10 lines of the output from another command:
ls -l | head
Using the head command is a straightforward way to quickly access the beginning of files in a terminal.
