What does the tail command do in UNIX?
a) Displays the last few lines of a file
b) Displays the first few lines of a file
c) Shows the contents of a file
d) Lists files in a directory
Answer:
a) Displays the last few lines of a file
Explanation:
The tail command in UNIX is used to display the last few lines of a file, similar to how head displays the first lines. By default, tail shows the last 10 lines, but you can specify a different number of lines with the -n option.
For example, tail -n 20 filename will display the last 20 lines of the file. The -f option can be used to continuously display new lines as they are added to the file, making it useful for monitoring log files in real time.
Knowing how to use tail is critical for working with logs and data streams. It allows users to easily keep track of the latest entries or updates without scrolling through the entire file.