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?

  1. Atail -f /var/log/app.log
  2. Bhead -n 10 /var/log/app.log
  3. 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.
Practice this topic Back to topic

Books on Linux and Command-Line Basics Ad

As an Amazon Associate I earn from qualifying purchases.

More Linux and Command-Line Basics questions

  1. Which of the following is the output of the command above, which extracts columns from a comma-separated line?
  2. Which of the following is the output of the sed command above, which replaces characters?
  3. In the session above, which of the following is printed by the last awk?
  4. Which of the following describes the files found when find /data -name "*.log" -mtime +7 -size +100M is run with GNU find?
  5. When stopping a process that has stopped responding, it is recommended to first use "kill <process ID>" and to use "kill -9 <process ID>" only if that does not end it. Which of the following is the reason?