Nobody reads a log of thousands of lines in full: you usually need the start, the end, or whatever is being written right now.
cat prints a whole file, which suits a short config. With a log of thousands of lines, the start scrolls off the screen. A long file is read in less from the lesson "Working comfortably in the terminal", or in parts:
Without -n, both commands show 10 lines. The last lines are last by position in the file. A log appends new records at the end, so that is usually where the fresh events are.
tail -f (f for follow) shows the end of the file and does not exit: it waits for lines to be appended and prints them at once. If no new records come, the terminal looks frozen: tail is waiting. Ctrl+C gets you out.
The service log has 50,000 lines. A colleague is about to restart the service, and you need to see what it writes. What do you run?
-
cat prints all 50,000 lines, and you have to dig the restart records out of the end of the output. cat cannot wait for new lines: it prints the file and exits.
-
It shows the last lines as of now, and the restart records appear later.
tail -fprints lines as they are written. -
head shows the start of the file, while a log appends new records at the end. Compare
head -n 2 service.logwithtail -n 2 service.log.
tail -f shows the end of the log and prints the lines the service appends later. Once you have seen what you need, leave with Ctrl+C.