text
tail
Prints the last part of files. Essential for log inspection, especially with the follow flag to stream new lines.
tail [OPTION]... [FILE]... Common flags
| Flag | Purpose |
|---|---|
| -n | Print the last N lines (use -n +N to start at line N) |
| -c | Print the last N bytes |
| -f | Follow the file as it grows |
| -F | Follow by name -- reopens after rotation/truncation |
| --pid | With -f, exit when the given PID dies |
Examples
tail -n 100 app.log Last 100 lines
tail -f /var/log/syslog Stream new lines as they arrive
tail -F app.log Follow across log rotation
tail -n +2 data.csv Skip the CSV header row
Gotcha
-f follows the file descriptor, so logrotate replacements are missed; use -F for rotated logs.
Related commands
head
Outputs the first part of files. Defaults to the first ten lines but can trim by any line or byte count.
cat
Concatenates files and prints them to standard output. Also useful as a simple viewer or to feed content into pipelines.
grep
Searches text for lines matching a regular expression. Central to log analysis and pipeline filtering.
sed
Stream editor that applies a small program to each line of input. Widely used for search-and-replace and inline file edits.
awk
Pattern-action language for processing columnar text. Excellent for reshaping tabular data, aggregating fields, and quick reports.