Once you can find files, the next skill is reading them — especially logs, without opening an editor.
cat and less #
cat dumps a whole file to the screen — fine for something short. For anything long, less lets you scroll one screen at a time instead of flooding your terminal.
cat notes.txt
less server.log
| Key | In less |
|---|---|
Space | Next page |
b | Previous page |
/keyword | Search |
q | Quit |
head and tail #
head server.log # first 10 lines
head -n 20 server.log # first 20 lines
tail server.log # last 10 lines
tail -n 20 server.log # last 20 lines
The one that matters most in DevOps:
tail -f /var/log/application.log. The -f means “follow” — new lines print live as they’re written. This is how you watch an app while it’s running, in real time. Ctrl+C to stop.grep — finding a needle in a log file #
If server.log contains a mix of INFO and ERROR lines, this pulls out only the errors:
grep ERROR server.log
grep -i error server.log # case-insensitive
grep -r "ERROR" logs/ # search every file under logs/