head: Head — Show the first N lines of a file (default 10). head shows the first lines of a file or command output, ten by default. head -n 20 export.csv shows the first twenty lines. It is a quick way to peek at large files without opening them completely. Checking the column headers of a CSV export, the start of a log, or the first records of a data dump takes a second.
Its counterpart tail shows the end of a file, and tail -f follows new lines as they are written, which is the classic way to watch a log live. In pipelines, head is useful for limiting output, as in sort access.log | uniq -c | sort -rn | head to see the ten most frequent lines. It also stops reading early, so it is fast even on huge files.
Use before running or suggesting shell commands with flags, especially destructive or broad ones (-f/--force, -r/-R recursive, -a/--all, -y/--yes, prune, --hard), and when a user asks what a flag means (-v, -q, -n/--dry-run, -h, -o, -p, -t, -u, -w, -x, -c, -i). Explains flags per tool and prefers dry runs and narrow scopes.
Master defensive Bash programming techniques for production-grade scripts. Use when writing robust shell scripts, CI/CD pipelines, or system utilities requiring fault tolerance and safety.