You work as the Network Administrator for Perfect Solutions Inc. The company has a Linux-based
network. You are a root user on the Red Hat operating system. You want to keep an eye on the
system log file /var/adm/messages. Which of the following commands should you use to read the
file in real time?
A.
tail -f /var/adm/messages
B.
tail /var/adm/messages
C.
cat /var/adm/messages
D.
tail -n 3 /var/adm/messages
Explanation:
Using the -f option causes tail to continue to display the file in real time, showing added lines to the
end of the file as they occur.
What is the tail -f command?
The tail command is used to display the last few lines of a text file or piped data. It has a special
command line option –f (follow) that allows a file to be monitored. Instead of displaying the last few
lines and exiting, tail displays the lines and then monitors the file. As new lines are added to the
file by another process, tail updates the display.
This is particularly useful for monitoring log files. The following command will display the last 10
lines of messages and append new lines to the display as new lines are added to messages: tail -f
/var/adm/messages
Answer option C is incorrect. The cat command simply shows the content of the file when it was
last opened, cat does not continue to show updates of the file.
Answer option D is incorrect. The tail -n 3 /var/adm/messages command is used to show most
recent entries in log file but it will not continue to show updates of the log file.
Answer option B is incorrect. The tail command will show the last few lines of the log file, but it willnot continue to show updates of the log file.