How to View a File's Contents Without Opening It on Linux

With cat, less, head and tail, and when to use each one.

Easy 1 min read Published on 2026 By Equipo SolucionaPC

Short files: cat

cat file.txt

Dumps the entire content straight into the terminal — handy for short files, awkward for long files that don't fit on one screen.

Long files: less

less file.txt

Lets you navigate page by page with the arrow keys, search text with /word, and quit with q — without dumping everything onto the screen at once.

Just the beginning or the end

head file.txt      # first 10 lines
tail file.txt       # last 10 lines
tail -f file.log    # follows the file live, useful for active logs

Tip: tail -f is especially useful for watching a log file while something is running — it shows new lines as they get written, without having to reopen the file each time.

Frequently asked questions

Which should I use for a very long file?

less, since it lets you navigate comfortably without dumping the entire content onto the screen at once the way cat does.

What exactly is tail -f for?

It shows in real time the new lines being added to a file, very useful for watching log files of something that's actively running.

Share: