Bird
Raised Fist0
Linux CLIscripting~20 mins

tail -f for live log monitoring in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Tail Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
What does tail -f /var/log/syslog do?

You run the command tail -f /var/log/syslog in a terminal. What will you see?

Linux CLI
tail -f /var/log/syslog
AIt shows the last 10 lines of the syslog file and then waits, showing new lines as they are added.
BIt deletes the syslog file and creates a new empty one.
CIt shows the entire syslog file from the beginning and then exits immediately.
DIt copies the syslog file to a backup location.
Attempts:
2 left
💡 Hint

Think about what -f means in tail.

💻 Command Output
intermediate
1:30remaining
What happens if you run tail -f /var/log/syslog and the file is deleted?

You start tail -f /var/log/syslog. While it is running, the syslog file is deleted by another process. What will tail do?

Linux CLI
tail -f /var/log/syslog
AIt automatically switches to another log file.
BIt immediately stops and exits with an error.
CIt shows an error and stops following the file but stays open.
DIt continues to show new lines if the file is recreated with the same name.
Attempts:
2 left
💡 Hint

Consider how tail -f tracks files by inode, not just name.

❓ Configuration
advanced
2:00remaining
How to limit tail -f to show only lines containing 'error' live?

You want to monitor a log file live but only see lines that contain the word 'error'. Which command will do this?

Atail -f /var/log/syslog | grep -v 'error'
Btail -f /var/log/syslog | grep 'error' -m 1
Ctail -f /var/log/syslog | grep --line-buffered 'error'
Dtail -f /var/log/syslog | grep 'error' --no-buffer
Attempts:
2 left
💡 Hint

Think about how to keep grep showing matches as they appear.

❓ Troubleshoot
advanced
2:00remaining
Why does tail -f stop showing new lines after log rotation?

You use tail -f /var/log/app.log to watch a log. After log rotation, no new lines appear. Why?

ABecause <code>tail -f</code> is still following the old file descriptor which no longer receives new data.
BBecause <code>tail</code> does not support files larger than 1GB.
CBecause the terminal lost connection to the server.
DBecause the log file was deleted and <code>tail</code> automatically exits.
Attempts:
2 left
💡 Hint

Think about how log rotation works and how tail -f tracks files.

✅ Best Practice
expert
2:30remaining
Which tool is best for live log monitoring with automatic handling of log rotation?

You want to monitor logs live and ensure the tool continues showing new lines even after log rotation. Which tool is best suited?

Aless
Bmultitail
Ccat
Dtail -f
Attempts:
2 left
💡 Hint

Consider tools designed for advanced log monitoring beyond basic tail.

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