Linux tail command with examples

In this article, we will learn Linux tail command with examples step by step.

Linux tail command is used to print last few lines of a file. By default, it prints last 10 lines of a file on standard output(terminal).

Linux tail command Syntax:

tail [option] file_name

Linux tail command options:

-c, --bytes=[+]NUM output the last NUM bytes; or use -c +NUM to output starting with byte NUM of each file -f, --follow[={name|descriptor}] output appended data as the file grows; an absent option argument means 'descriptor' -F same as --follow=name --retry -n, --lines=[+]NUM output the last NUM lines, instead of the last 10; or use -n +NUM to output starting with line NUM --max-unchanged-stats=N with --follow=name, reopen a FILE which has not --pid=PID with -f, terminate after process ID, PID dies -q, --quiet, --silent never output headers giving file names --retry keep trying to open a file if it is inaccessible -s, --sleep-interval=N with -f, sleep for approximately N seconds (default 1.0) between iterations; with ino‐ tify and --pid=P, check process P at least once every N seconds -v, --verbose always output headers giving file names -z, --zero-terminated line delimiter is NUL, not newline

Linux tail command examples

1. To view last 10 lines of file in Linux:

tail less.txt

2. To view last 100 lines of file.

tail -200 less.txt

3. Tail command with -f option.

Outputs the last 10 lines of file and monitors the file for updates; tail then continues to output any new lines that are added to the file.

tail -f less.txt

Linux tail command with examples

Press Ctrl+C to quit from the file.

4. To print last lines of more than a file.

tail less.txt more.txt