Linux and Command-Line Basics
You want to keep showing lines on the screen as they are appended later to the server log file /var/log/app.log. Which of the following commands is appropriate?
- Atail -f /var/log/app.log
- Bhead -n 10 /var/log/app.log
- Ccat /var/log/app.log
Show answer and explanation
Answer: A. tail -f /var/log/app.log
tail shows the last lines of a file (10 by default); with -f (follow) it does not exit after showing them but keeps watching the file and shows appended lines as they arrive. It is often used to follow the progress of a simulation or job through its log, and Ctrl+C stops it. When the log is rotated to a different name, tail -F, which keeps following a new file with the same name, is convenient. head shows the first lines and cat the whole file once, and then they exit.
- A. Correct. With -f it keeps showing appended lines.
- B. head -n 10 shows the first 10 lines once and does not show appended lines.
- C. cat shows the contents at that moment once and exits; it does not show lines appended later.