head Command Reference for CI Scripts
head shows the beginning of a file or stream, the first 10 lines by default.
head is a trivial command with one non-trivial CI interaction: when it closes a pipe early, the upstream process gets SIGPIPE, which with set -o pipefail can fail the step.
Common flags/usage
- -n N: first N lines (-N also works)
- -n -N: all but the last N lines (GNU)
- -c N: first N bytes
- -q / -v: never / always print file headers
Example
shell
head -n 50 build.log
curl -fsS "${API}/data" | head -c 2000 # preview a responseIn CI
When head exits after N lines it closes the pipe, sending SIGPIPE to the producer, which exits 141 (128+13). With set -o pipefail, cmd | head can make the whole pipeline "fail" even though it worked; handle it deliberately. Negative counts and -c byte mode are GNU features absent on some BusyBox builds.
Key takeaways
- head -n N previews the first N lines; -c N previews bytes.
- Under pipefail, cmd | head can fail the step via SIGPIPE (exit 141).
- Negative line counts are a GNU feature missing on BusyBox.
Related guides
tail Command Reference for CI Scriptstail prints the last lines of input or follows a growing file in CI. Reference for -n, -f, and +N, plus the -…
set -euo pipefail Reference for CI Scriptsset -euo pipefail makes bash CI scripts fail fast. Reference for -e exit-on-error, -u unset-var, and pipefail…
sort Command Reference for CI Scriptssort orders lines of text in CI for stable diffs. Reference for -n, -u, -k, -t, and -r, plus the locale gotch…
wc Command Reference for CI Scriptswc counts lines, words, and bytes in CI. Reference for -l, -w, -c, and -m, plus the leading-whitespace gotcha…