Skip to content
Latchkey

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 response

In 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →