Back to course

20. Viewing File Content: The `tail`, `more`, and `less` Commands

Linux Basics: From Zero to CLI Hero

Viewing Endings and Large Files

3. tail

tail displays the ending lines of a file (the 'tail'). It is extremely useful for viewing log files, as new entries are written to the end.

  • Default: last 10 lines. bash $ tail /var/log/syslog

  • View the last 20 lines: bash $ tail -n 20 /var/log/syslog

Monitoring Files (tail -f)

The -f (follow) option keeps the file open and displays new lines as they are added, perfect for real-time monitoring of logs.

bash $ tail -f /var/log/syslog

4. less and more (Pagers)

These commands are essential for viewing large files, as they display the content one screenful at a time (paging).

  • less is superior to more because it allows backward navigation.

bash $ less /var/log/boot.log

Inside less:

  • Spacebar: Scroll down one page.
  • b: Scroll up one page.
  • /search_term: Search forward for text.
  • n: Go to the next search match.
  • q: Quit and return to the shell prompt.