How to view file contents

Overview

Different viewing tools suit different file sizes. cat prints a whole file, while less lets you navigate without loading the entire file into your terminal.

Examples

cat notes.txt
less /var/log/dpkg.log
head -n 20 notes.txt
tail -n 20 notes.txt
tail -f app.log

Choose a command

  • cat is best for short files
  • less supports scrolling, / search, and q to quit
  • head shows the beginning
  • tail shows the end
  • tail -f follows new lines written to a log; stop with Ctrl+C

Tips

These commands display binary files poorly and may garble the terminal. Use file name first when the format is uncertain.

Permission errors mean your user cannot read the file; do not use sudo unless the file is trusted and access is appropriate.