Home·Terminal commands

tail

Files and directories

Usage

tail -f [file]

Prints the end of a file and keeps watching it with -f; only -F reopens the file after a log rotation.

Common flags

FlagMeaning
-nPrint the last N lines
-n +NStart at line N instead of counting from the end
-fKeep printing as the file grows
-FFollow by name and reopen the file after log rotation
-cPrint the last N bytes
-rBSD: print the lines in reverse order (GNU uses tac)

Examples

tail -f app.log

Watches a log live; Ctrl-C stops.

tail -n +2 data.csv

Skips the header line.

tail -F /var/log/nginx/access.log

Keeps following after the log is rotated.

Moving, deleting and finding. Some of these do not ask twice, which is why -i becomes a habit.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does tail do?

Prints the end of a file and keeps watching it with -f; only -F reopens the file after a log rotation.

Q. How do I type it?

tail -f [file] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

6 are listed here; the full set is in man tail. This command sits under Files and directories.

Related commands

man page: man tail