Reading and Viewing Files¶
Commands for viewing file contents without editing.
Command |
Description |
Examples |
|---|---|---|
|
Display entire file |
|
|
First 10 lines (default) |
|
|
Last 10 lines (default) |
|
Common Patterns¶
cat file.txt # Show all
head -n 20 file.txt # First 20 lines
tail -n 20 file.txt # Last 20 lines
tail -f log.txt # Follow log in real-time
Tips¶
tail -fis perfect for watching log files update in real-timeUse
headandtailfor large files to avoid scrolling through everythingCombine with
lessfor paginated viewing:less largefile.txtUse
morefor simpler pagination:more largefile.txt