Almost everything on a Linux system is configured with a text file and diagnosed with a text file. Reading them quickly is a genuine skill, and it starts with knowing which of four tools to reach for.
cat dumps a whole file to the screen. Perfect for short files, terrible for long ones — a 5,000-line log will scroll past faster than you can read and leave you at the bottom.
cat /etc/hostname
less opens a file in a pager you can scroll and search. This is the right default for anything you can't see in one screen.
less /var/log/syslog
Inside less: arrow keys or Space to scroll, /word to search forwards, n for the next match, G to jump to the end, g for the start, and q to quit. That last one matters — being stuck in a pager with no idea how to leave is a rite of passage nobody enjoys.
head and tail show you the first or last ten lines:
head -n 20 access.log # first 20 lines
tail -n 50 access.log # last 50 lines
tail -f is the one you'll use most in real work. It shows the end of a file and then keeps watching, printing new lines as they're written:
tail -f /var/log/nginx/error.log
Leave that running in one window, reproduce your bug in another, and watch the error appear in real time. Ctrl+C stops it.
This one is a recording — the commands are real, but nothing is running here. Type them into your own shell to follow along.
You need to watch a log file as new entries arrive while you reproduce a bug. Which command?
Sooner or later you'll need to change a config file on a machine that has no GUI. You have two realistic options.
nano config.txt
nano behaves the way you expect a text editor to behave. Type to insert, arrow keys to move. The commands are listed along the bottom of the screen, where ^ means Ctrl:
If nano is available, use it. There is no prize for suffering.
vim is on essentially every Unix machine ever built, including minimal containers and rescue images where nano isn't installed. You don't need to learn vim properly today. You need to not be trapped by it.
The one idea that makes vim make sense: it has modes. When it opens you are in normal mode, where keys are commands, not text. This is why typing "hello" into a fresh vim does something alarming instead of writing "hello".
The survival sequence:
:wq and Enter to write and quit.:q! and Enter to quit and throw away every change.That's it. Esc, then :wq to save or :q! to bail. Those four keystrokes get you out of any vim session you didn't mean to start.
:q! need the exclamation mark?Because vim refuses to discard unsaved work quietly.
Plain :q means "quit". If the file has unsaved changes, vim declines and warns you. The ! means "I know, do it anyway" — it's the same force idea as -f in rm -rf or cp -f.
The pattern shows up all over Unix: the safe version is the default, and you add something explicit to override the safety. Once you notice it, ! and -f stop looking arbitrary.
Show the last 100 lines of a file called access.log.
You've opened vim by accident and typed some junk. How do you leave without saving?
Next: permissions — the reason things say "Permission denied", and what rwx actually means.
