Which command is used to display the content of a file in reverse order?
a) tac
b) cat
c) head
d) tail
Answer:
a) tac
Explanation:
The tac
command in UNIX is used to display the content of a file in reverse order. It is the reverse of the cat
command, which displays file content normally. Using tac
, the last line of the file is shown first, followed by the preceding lines in reverse sequence.
For example, running tac filename
will display the file’s contents starting from the last line. This is useful when you want to examine the latest entries in log files or data sets where the most recent information is at the end of the file.
Understanding the tac
command is helpful for working with files that are structured chronologically or sequentially. It provides an alternative view of file content, making it easier to analyze data from a different perspective.