←  linux commands

Views:

tail command

The tail command is used to output last lines of a file.

Syntax: tail [options] file

Example:

tail main.js
tail-output

Options:

-n Prints last n lines of a file.

Example:

tail -n 3 main.js
tail-n-output

Example: Printing line from X to Y using head and tail command.

Suppose we have to print from line 5 to line 7, Here, X is 5 and Y is 7. We can use following command to print it-

# Here, X and Y are starting line number and ending line number respectively.
head -n Y main.js | tail -n Y-X+1

So, for outputing line 5 to 7, command would be:

head -n 7 main.js | tail -n 3
head-tail-output