0
0
Linux CLIscripting~20 mins

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

Choose your learning style9 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.