Bird
Raised Fist0
Linux CLIscripting~10 mins

tail -f for live log monitoring in Linux CLI - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the command to continuously watch the end of a log file named app.log.

Linux CLI
tail [1] app.log
Drag options to blanks, or click blank then click option'
A-f
B-c
C-n
D-v
Attempts:
3 left
💡 Hint
Common Mistakes
Using -n shows last lines but does not follow live updates.
Using -c shows bytes, not lines.
Using -v is for verbose output, not live monitoring.
2fill in blank
medium

Complete the command to follow server.log and show the last 20 lines initially.

Linux CLI
tail [1] 20 -f server.log
Drag options to blanks, or click blank then click option'
A-n
B-c
C-v
D-q
Attempts:
3 left
💡 Hint
Common Mistakes
Using -c shows bytes, not lines.
Using -v or -q do not control line count.
3fill in blank
hard

Fix the error in the command to follow error.log live: tail -n -f 10 error.log. Place the correct option to make it work.

Linux CLI
tail [1] 10 error.log
Drag options to blanks, or click blank then click option'
A-n
B-n -f
C-f -n
D-f
Attempts:
3 left
💡 Hint
Common Mistakes
Putting -n before -f without a number causes errors.
Using only -f shows last 10 lines by default, but here 10 lines are requested.
4fill in blank
hard

Fill both blanks to create a command that follows access.log and shows the last 50 lines initially.

Linux CLI
tail [1] [2] -f access.log
Drag options to blanks, or click blank then click option'
A-f
B-n
C50
D-v
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the number before the option.
Using -v which does not control lines or following.
5fill in blank
hard

Fill all three blanks to create a command that follows debug.log, shows last 30 lines, and uses verbose output.

Linux CLI
tail [1] [2] [3] -f debug.log
Drag options to blanks, or click blank then click option'
A-f
B-n
C30
D-v
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the verbose option.
Placing the number before the -n option.

Practice

(1/5)
1. What does the command tail -f /var/log/syslog do?
easy
A. Copies the syslog file to another location
B. Deletes the syslog file permanently
C. Shows the last lines of the syslog file and updates live as new lines are added
D. Shows the first lines of the syslog file only once

Solution

  1. Step 1: Understand the tail command

    The tail command shows the last part of a file.
  2. Step 2: Understand the -f option

    The -f option makes tail keep running and show new lines as they are added to the file.
  3. Final Answer:

    Shows the last lines of the syslog file and updates live as new lines are added -> Option C
  4. Quick Check:

    tail -f = live log monitoring [OK]
Hint: Remember: -f means follow new lines live [OK]
Common Mistakes:
  • Thinking tail -f deletes or copies files
  • Confusing tail with head
  • Expecting tail -f to show the start of the file
2. Which of the following is the correct syntax to continuously monitor the file /var/log/auth.log using tail?
easy
A. tail -n /var/log/auth.log
B. tail /var/log/auth.log -f
C. tail -follow /var/log/auth.log
D. tail -f /var/log/auth.log

Solution

  1. Step 1: Identify correct option placement

    The option -f must come immediately after tail before the filename.
  2. Step 2: Verify option correctness

    -f is the correct option to follow the file live; -follow is invalid and -n requires a number.
  3. Final Answer:

    tail -f /var/log/auth.log -> Option D
  4. Quick Check:

    Correct syntax = tail -f /var/log/auth.log [OK]
Hint: Options come before filename; -f not -follow [OK]
Common Mistakes:
  • Placing options after filename
  • Using invalid option -follow
  • Using -n without a number
3. You run tail -f /var/log/app.log and see the following output after new log entries are added:
ERROR: Connection failed
INFO: Retrying connection
SUCCESS: Connected

What does this output indicate?
medium
A. The application is logging connection attempts and success live
B. The log file is empty and no new entries are added
C. The command failed to read the log file
D. The log file is being deleted while monitoring

Solution

  1. Step 1: Understand tail -f output

    The command shows new lines added live to the log file.
  2. Step 2: Interpret the log messages

    The messages show connection failure, retry, and success, indicating live logging of connection status.
  3. Final Answer:

    The application is logging connection attempts and success live -> Option A
  4. Quick Check:

    Live log updates = The application is logging connection attempts and success live [OK]
Hint: New lines mean live updates from the app log [OK]
Common Mistakes:
  • Thinking the log file is empty
  • Assuming command failed without error message
  • Confusing deletion with normal log updates
4. You try to run tail -f /var/log/app.log but get the error: tail: cannot open '/var/log/app.log' for reading: Permission denied. What should you do to fix this?
medium
A. Delete the log file and try again
B. Run the command with sudo to get permission
C. Use head -f instead
D. Restart the system to fix permissions

Solution

  1. Step 1: Understand the error message

    The error says permission denied, meaning the current user cannot read the file.
  2. Step 2: Fix permission issue

    Running the command with sudo gives temporary admin rights to read the file.
  3. Final Answer:

    Run the command with sudo to get permission -> Option B
  4. Quick Check:

    Permission denied fix = use sudo [OK]
Hint: Permission denied? Try sudo before the command [OK]
Common Mistakes:
  • Deleting the log file unnecessarily
  • Using head -f which is invalid
  • Restarting system without checking permissions
5. You want to monitor two log files live at the same time: /var/log/nginx/access.log and /var/log/nginx/error.log. Which command will correctly do this?
hard
A. tail -f /var/log/nginx/access.log /var/log/nginx/error.log
B. tail -f /var/log/nginx/access.log && tail -f /var/log/nginx/error.log
C. tail -f /var/log/nginx/access.log | tail -f /var/log/nginx/error.log
D. tail -f /var/log/nginx/access.log; tail -f /var/log/nginx/error.log

Solution

  1. Step 1: Understand how to monitor multiple files

    tail -f accepts multiple filenames to follow them simultaneously in one terminal.
  2. Step 2: Analyze each option

    tail -f /var/log/nginx/access.log /var/log/nginx/error.log correctly lists both files after tail -f. Using && or ; runs commands sequentially, so the second starts after the first ends. Piping two tail -f commands with | is invalid for this purpose.
  3. Final Answer:

    tail -f /var/log/nginx/access.log /var/log/nginx/error.log -> Option A
  4. Quick Check:

    Multiple files = list all after tail -f [OK]
Hint: List all files after tail -f to watch together [OK]
Common Mistakes:
  • Using && or ; runs commands one after another, not together
  • Piping two tail -f commands is invalid
  • Trying to monitor files separately in one terminal
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard