Problem Statement
What does the tail -f command do?
Explanation
Tail -f (follow) displays the last 10 lines of a file by default and continues monitoring the file, displaying new lines as they're appended. This is invaluable for monitoring log files in real-time, seeing application output, or watching file updates without repeatedly running commands. Press Ctrl+C to stop following.
Tail without -f shows the last 10 lines and exits. Use -n option to specify number of lines: tail -n 20 file.log shows last 20 lines. Head does the opposite, showing first lines: head -n 20 file.log shows first 20 lines. Both commands accept input from pipes: ps aux | head -20 shows first 20 processes.
Common usage: tail -f /var/log/syslog for system log monitoring, tail -f /var/log/apache2/error.log for web server debugging. Use tail -F (capital F) to continue following even if the file is rotated (deleted and recreated), important for log files that get rotated. Understanding tail -f is essential for troubleshooting and monitoring production systems.
