Viewing the end of a file on Unix/Linux: Which command displays the tail (last lines) of a text file on the terminal by default?
-
Ahead -r
-
Btail
-
Ceof
-
Dbof
-
ENone of the above
Answer
Correct Answer: tail
Explanation
Introduction / Context:When troubleshooting logs or monitoring activity, it is often necessary to see the most recent lines appended to a file. Unix provides a dedicated utility for this purpose, enabling both static viewing and live following.
Given Data / Assumptions:
- We want the command that shows the end of a file.
- Default behavior should display the last 10 lines unless otherwise specified.
- We are using standard Unix command-line tools.
Concept / Approach:
The tail utility prints the final portion of files. Common flags include -n for a specific number of lines and -f to follow file growth in real time (useful for log monitoring). Other listed options either do something else or are not valid commands.
Step-by-Step Solution:
Identify the canonical tool: 'tail'.Recall default behavior: displays last 10 lines.Optional usage: tail -n 50 file.txt or tail -f /var/log/syslog to follow updates.Conclude that 'tail' is the required command.Verification / Alternative check:
Running tail /etc/passwd on a Unix system prints the last 10 entries. Adding -f keeps the file open and prints new additions as they occur, confirming its role for end-of-file viewing.
Why Other Options Are Wrong:
- head -r: head shows the beginning of a file; '-r' is not portable and still would not show the tail.
- eof, bof: Not standard Unix commands; EOF/BOF are concepts, not executables.
- None of the above: Incorrect because 'tail' is correct.
Common Pitfalls:
Confusing 'head' and 'tail'; expecting -f to terminate automatically; forgetting to use sudo or appropriate permissions when tailing protected logs.
Final Answer:
tail