How do I view the last 100 lines of a log file?

Updated October 2026 · How we answer

Short answerRun tail with the -n option followed by the number of lines, such as tail -n 100 followed by the file path. Add -f to keep watching the file as new lines are written.

Using tail for recent lines

The tail command prints the end of a file, which is where the newest entries usually appear. The -n flag sets how many lines to show, and the file path comes last. For a quick check after a deploy, this is often the fastest command you can run.

  • tail -n 100 /path/to/file.log for the last hundred lines
  • tail -f /path/to/file.log to follow new entries live
  • Combine with grep to filter for errors

Reading longer logs

For a large file, less lets you scroll and search without loading everything into your terminal at once. Press capital G to jump to the end and slash followed by a word to search. Piping output through grep narrows the view to just the lines that matter.

Permissions and paths

Some log files belong to root or a service account, so you may need sudo to read them. Confirm the exact path first, since many services write logs to a directory rather than a single file. If the file is empty, check whether the service logs to the system journal instead.

Common mistakes

  • Forgetting sudo and reading a permissions error as an empty file.
  • Running tail -f on a huge file without limiting the output first.
  • Looking in the wrong directory when the service writes to the journal.
From our shopsTitan Case: Premium MagSafe iPhone cases with a precision fit.