CMD Master
Back to Blog
Arnošt Havelka

Read files with cat and less

Dump a short file with cat, then page through a long file with less.

Start Interactive Lesson
Read files with cat and less

Short 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.

Try the command

Print a short file!

Build the command
cat
Terminal
C:\Users\User>cat short.txt

See the whole note:

Command Prompt
C:\Users\User>cat short.txt

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.

Command Prompt
C:\Users\User>less long.txt

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 / 3

When should you prefer cat?

References

These documentation links provide authoritative details for the commands used in this article.

Up Next

Check disk space and memory in Bash

See free disk with df -h, folder size with du -sh, and RAM with free -m.