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 followIn 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
head Command Reference for CI Scriptshead prints the first lines or bytes of input in CI. Reference for -n, -c, and negative counts, plus the SIGP…
timeout Command Reference for CI Scriptstimeout caps how long a command may run in CI, preventing hangs. Reference for duration units, -k kill-after,…
tee Command Reference for CI Scriptstee writes stdin to a file and stdout at once in CI logging. Reference for -a append, multiple files, and 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…