head and tail

Intro

Simple, extensible file previewers.

Beginning of a File - head

  • head big.txt - first 10 lines
  • head -n 3 big.txt - first 3 lines
  • head -n -5 big.txt - up to the 5th-to-last line (exclusive)

End of a File - tail

  • tail big.txt - last 10 lines
  • tail -n 3 big.txt - last 3 lines
  • tail -n +5 big.txt - starting at the 5th line (inclusive)

Following Output

tail also comes with a follow output feature. This can be useful when watching logging/output files written to in real-time by other programs.

  • tail -f output.txt - last 10 lines and print new lines when they are written
  • tail -n +0 -f output.txt - all lines and print new lines when they are written

See Also

  • man head
  • man tail
beefslab