Skip to content
Latchkey

tail Command Reference for CI Scripts

tail shows the end of a file and, with -f, streams new lines as they arrive.

tail is great for surfacing the last few lines of a log. The CI hazard is tail -f, which never returns on its own and will hang a job until it times out.

Common flags/usage

  • -n N: last N lines
  • -n +N: start at line N (skip a header)
  • -f / -F: follow the file (-F survives rotation)
  • -c N: last N bytes

Example

shell
tail -n 100 "${LOG_DIR}/app.log"
tail -n +2 data.csv | sort        # skip a header row before sorting
timeout 30 tail -f deploy.log     # bounded follow

In CI

tail -f blocks forever and in a pipeline stalls the job until the CI timeout kills it; wrap it with timeout, run the producer in the background, or tail the file once after the process exits. Do not confuse -n +N (start at line N) with -n N (last N lines).

Using this in CI

A runner shell is not a login shell. It does not read your dotfiles, it usually has no TTY, and by default it does not stop on the first error, so a failing command in the middle of a multi-line run block can leave the job green.

.github/workflows/ci.yml
# make the shell behave the way you assume it does
- name: Build
  shell: bash
  run: |
    set -euo pipefail    # exit on error, undefined vars, and pipeline failures
    ./do-the-thing | tee out.log

Key takeaways

  • tail -f never exits on its own; wrap it with timeout in CI.
  • -n +2 skips a header row; -n 100 shows the last 100 lines.
  • Use -F instead of -f to keep following across log rotation.

Frequently asked questions

tail Command Reference for CI Scripts?
tail is great for surfacing the last few lines of a log. The CI hazard is tail -f, which never returns on its own and will hang a job until it times out.
In CI?
tail -f blocks forever and in a pipeline stalls the job until the CI timeout kills it; wrap it with timeout, run the producer in the background, or tail the file once after the process exits. Do not confuse -n +N (start at line N) with -n N (last N lines).

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card