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
| Flag | Meaning |
|---|---|
| -n | Print the last N lines |
| -n +N | Start at line N instead of counting from the end |
| -f | Keep printing as the file grows |
| -F | Follow by name and reopen the file after log rotation |
| -c | Print the last N bytes |
| -r | BSD: print the lines in reverse order (GNU uses tac) |
Examples
tail -f app.logWatches a log live; Ctrl-C stops.
tail -n +2 data.csvSkips the header line.
tail -F /var/log/nginx/access.logKeeps 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