Linux for Developers
/Beginner
tail -f
Definition
A command combination used to output the last 10 lines of a file, and then crucially, 'follow' the file, dynamically printing any new lines added to the file in real-time.
Explain Like I'm New
Watching a live security camera. As a server writes new errors to the log file, they instantly pop up on your screen.
Real World Example
A developer deploys new code to a live website. They type `tail -f /var/log/nginx/error.log`. As real users start hitting the website, any bugs or errors instantly stream down the developer's screen live.
Common Use Cases
- •Live debugging
- •Monitoring application health during deployments
Crucial Command Flags
| Flag / Option | Description |
|---|---|
| -f | Follow by file descriptor (breaks if file is rotated). |
| -F | Follow by filename (survives log rotations/deletions). |
| -n [num] | Start by showing the last [num] lines before following. |
Interview Questions
basic
- How do you stop the `tail -f` command and return to the normal terminal prompt?
intermediate
- If a log rotation script deletes the file you are currently `tail`ing and creates a new empty file with the same name, what happens to your `tail -f` command?