Read files with cat and less
Dump a short file with cat, then page through a long file with less.
Start Interactive LessonShort files are easy to print all at once. Long files scroll off the screen. Bash gives you both tools: cat for a full dump, and less for paging.
Print the whole file: cat
cat writes every line to the terminal. Use it when the file fits on one or two screens.
Print a short file!
See the whole note:
Page through a long file: less
less opens the file in a pager. Space moves down a screen, arrow keys move line by line, and q quits. The terminal is not flooded.
mkdir -p terminal-demo
printf '%s\n' 'Line 1' 'Line 2' 'Line 3' > terminal-demo/long.txt
less terminal-demo/long.txt
That is the right default for logs, manuals, and anything you are not sure will fit.
Rule of thumb: cat when you want everything immediately; less when you want to walk through the file. You can still search inside less with /pattern.
Knowledge Check
1 / 3When should you prefer cat?
References
These documentation links provide authoritative details for the commands used in this article.
Up Next
See free disk with df -h, folder size with du -sh, and RAM with free -m.