Lesson 4: Reading files — cat, head, tail
We can already find our way around and move between directories. Now comes the part you'll do most in DevOps — reading what's inside files: config files and log files. We'll meet three commands: cat prints the whole file (great for short files), head the first lines, and tail the last lines — where,
cat is dumping the whole page on the table. head reads just the top of the page, and tail just the bottom — where the freshest news is. tail -f is to keep staring at the bottom while more is being written there, like a live news ticker.
- cat
- Prints a file's entire contents at once. Great for short files (config); for a huge file it floods the screen.
- head
- Prints the first lines of a file (10 by default). head -n 3 prints the first 3.
- tail
- Prints the last lines of a file (10 by default) — where a log's newest entries are.
- tail -f (live follow)
- Pins you to the end of a log and keeps printing new lines as they're written. Exit with Ctrl+C.