Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux tail Command

Linux tail Command

Linux Command Reference Linux Command Reference

The tail command can be used to view file contents; a commonly used parameter, -f, is often used to inspect log files that are changing.

tail -f filename displays the very end of the filename file on screen and keeps refreshing, so you can see the latest file content whenever filename is updated.

If you need to view the beginning of a file, use the command head.

Command format:

tail [参数] [文件]  

Parameters:

Example

To display the last 10 lines of notes.log, enter the following command:

tail notes.log         # 默认显示最后 10 行

To track the growth of a file named notes.log, enter the following command:

tail -f notes.log

This command displays the last 10 lines of the notes.log file. As new lines are added to notes.log, the tail command will keep displaying them. Display continues until you press (Ctrl-C) to stop.

Display the contents of notes.log from line 20 to the end of the file:

tail -n +20 notes.log

Display the last 10 characters of notes.log:

tail -c 10 notes.log

Linux Command Reference Linux Command Reference