Frequently Asked Question
What is the difference between head, tail, and tail -f?
head prints the first lines of a file (10 by default; head -n 20 for 20).
tail prints the last lines of a file (also 10 by default). Both are useful for
peeking at the shape of a file without scrolling the terminal. head is
typically used at the end of a pipeline to limit output to the top N results,
as in sort -rn | head to grab the top ten.
tail -f (for follow) is the killer feature: it prints the last lines of the
file and then keeps watching, printing each new line as it is appended.
Running tail -f /var/log/syslog in one terminal window while you debug a
service in another is a standard sysadmin posture, every error the service
logs appears in real time. tail -F (capital F) is similar but copes with log
rotation: if the file is replaced or truncated, it reopens the new file rather
than silently watching the dead inode.