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).

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.

Related guides

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