Difficulty: Easy
Correct Answer: tail
Explanation:
Introduction / Context:Log inspection and troubleshooting often require viewing the most recent lines of a growing file. Unix provides a simple utility that, by default, shows the last 10 lines and can follow a file as it grows in real time, making it indispensable for monitoring logs and long-running processes.
Given Data / Assumptions:
Concept / Approach:
The tail command prints the end of files. With no options, it outputs the last 10 lines. Adding -n changes the number of lines, and -f follows the file, printing appended data in real time, which is ideal for tailing logs during service restarts or deployments.
Step-by-Step Solution:
Run tail /var/log/some.log to see the last 10 lines.Use tail -n 50 file to see the last 50 lines.Use tail -f file to follow new lines as they are written.Combine with grep: tail -f file | grep pattern for live filtering.Verification / Alternative check:
Compare with head (first lines) to understand the difference. cat shows the whole file, which is inefficient for very large logs when only the end is needed.
Why Other Options Are Wrong:
Common Pitfalls:
Forgetting -n when a different count is required, using tail -f without stopping it in scripts, and tailing the wrong rotated log file. Use tail -F to handle log rotations gracefully.
Final Answer:
tail
Discussion & Comments