Category: Advanced – Command Line • Est. reading time: 1 minute
The head command prints the beginning of a file, the first 10 lines by default. It is handy for peeking at a large file without opening the whole thing.
View the first 10 lines
head textFile.txt
View the first 50 lines
head -50 textFile.txt # or: head -n 50 textFile.txt
Pull a range of lines with tail and head
For a file with 70 lines, this shows lines 21 to 30. The tail part keeps the last 50 lines (21 to 70), then head keeps the first 10 of those.
tail -50 textFile.txt | head -10
Related: for the end of a file use the tail command, and for paging through a whole file see the less command.
Running your own dedicated or self-managed server? We are glad to help. Reach us at support@allydrez.com or 1-321-209-2004.