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
catis best for short fileslesssupports scrolling,/search, andqto quitheadshows the beginningtailshows the endtail -ffollows 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.