Lesson 7 / 29
Viewing File Contents
cat, less, head and tail.
cat — dump the whole file
cat prints a file's entire contents to the screen — fine for short files.
cat /etc/hostname
Output:
ubuntu-server
less — page through big files
less opens a file for scrollable viewing without loading it all into memory. Press q to quit, /word to search.
less /var/log/sysloghead & tail
head shows the first lines, tail the last. tail -f follows a growing file live — great for watching logs.
head -n 5 access.log
tail -f access.logQuick check: Which command lets you watch a log file update live?
- cat log.txt
- tail -f log.txt
- head log.txt
Answer
tail -f log.txt — `tail -f` keeps the file open and prints new lines as they're appended.