Linux tail

This command is used to display the last lines of a file. The main purpose of this command is to read the error message. And it will also show the last ten lines of a file by default.

Syntax:

tail <file name>

Example: tail jtp.txt

codes@w3schools:~/Desktop$ tail jtp.txt
 
c
 
d
 
e
 
f
 
g
 
h
 
i
 
j
 
k
 
l
 
mmmmm
 
nnnnn

In the above example, the last ten lines of the file ‘jtp.txt’ are displayed when we used “tail jtp.txt” command.

Linux tail –n:

This ‘tail -n’ option shows the specified number of lines.

Syntax:

tail -n<number> <file name>

Example: tail -n5 jtp.txt

codes@w3schools:~/Desktop$ tail -n5 jtp.txt
 
c
 
d
 
e
 
f
 
g
 
h
 
i
 
j
 
k
 
l
 
mmmmm
 
nnnnn

As we can see in the above example, the last five lines of the file ‘jtp.txt’ are displayed on the screen after we used “tail -n5 jtp.txt” command.

tail –c:

The specified number of bytes from the last of the file will be displayed on using ‘tail -c’ option.

Syntax:

tail -c<number> <file name>

Example: tail -c12 jtp.txt

codes@w3schools:~/Desktop$ tail -c12 jtp.txt
 
mmmmm
 
nnnnn

In the above example, when we used “tail -c12 jtp.txt” command, the last 12 bytes of file ‘jtp.txt’ is displayed on the screen.

 

Please follow and like us:
Content Protection by DMCA.com