Back to the command reference

tail

FilesBeginner In simulator In real Linux

Print the last lines of files

Name: tail

You can practise it right away in the simulator, and use it in real Linux mode too.

Description

tail prints the end of a file, the last 10 lines by default. -n +N starts at line N instead, handy for skipping a header.

-f (follow) keeps waiting and prints new lines as they are appended, the classic way to watch a log; -F also survives log rotation.

Syntax

tail [OPTION]... [FILE]...

Common options

-n / --lines [+]NUMLast N lines (default 10); +N starts at line N
-c / --bytes [+]NUMShow the last NUM bytes; +NUM starts at byte NUM
-f / --followFollow the file as it grows; great for logs
-FFollow the name: keep going when the file is replaced (log rotation)
--pid PIDWith -f: stop when process PID ends
-q / --quietWith several files, leave out the name headers

Examples

  • $ tail -n 2 logs/app.log

    Last 2 lines of the log

    Explain
  • $ tail -n +2 data/scores.csv

    Skip the first (header) line

    Explain

Related