Skip to content

tail

9 commands

Prints the last lines of files and follows them as they grow — the standard way to watch logs.

  • logs
  • text

Install tail

sudo apt install coreutils

Basics4

tail <file>

Prints the last 10 lines.

Link
tail -n <n> <file>

Prints the last n lines.

Link
tail -n +<n> <file>

Prints from line n onward — here, everything after a CSV header.

Link
tail -c <bytes> <file>

Prints the last n bytes.

Link

Following logs5

tail -f <file>

Follows a file as new lines are written. Ctrl-C to stop.

Link
tail -F <file>

Follows by name and reopens the file when it is rotated — use this for long-running watches.

Link
tail -f <file1> <file2>

Follows several files at once with headers.

Link
tail -f <file> | grep --line-buffered <pattern>

Watches only for matching lines, such as failed SSH logins, as they happen.

Link
tail -f --pid=<pid> <file>

Stops following when the given process exits.

Link