How do you display the last few lines of a file?

Answer

Use tail filename which shows the last 10 lines by default. tail -n 50 filename shows the last 50 lines. tail -f filename (follow mode) continuously streams new content as it is appended — invaluable for monitoring log files in real time (e.g., tail -f /var/log/nginx/access.log). tail -F filename is like -f but also handles log rotation by reopening the file if it is recreated. Combine with grep: tail -f app.log | grep ERROR to filter real-time log output.