head show the first lines
head prints the beginning of a file, 10 lines by default. Use it to peek at a file's header and format before you write a query, or to take a quick sample of a huge file.
Availability Preinstalled on macOS, Linux and BSD
Syntax
head [-n count] [file ...]
Common options
| Option | What it does |
|---|---|
-n N | Print the first N lines (default 10) |
-c N | Print the first N bytes |
Examples
See the header row of a CSV
head -n 1 users.csv
Peek at the first records
head -n 5 events.jsonl
Use head with sqx
Try a query on a sample first
Test a slow or complex query on the first thousand lines of a big file, then run it on everything.
head -n 1000 big.csv | sqx "SELECT country, COUNT(*) FROM stdin GROUP BY country"
Look at the first rows of a result
sqx -f events=events.jsonl -o csv "SELECT * FROM events ORDER BY amount DESC" | head -n 4
In SQL, LIMIT does the same job inside the query: SELECT * FROM stdin LIMIT 10.
Full documentation
This page covers the essentials. For every option, see the official documentation:
Or read the manual in your terminal: man head