Linux tail Command
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:
- -f Read continuously
- -q Do not display processing information
- -v Display detailed processing information
- -c
Number of bytes to display - -n
Display the last n lines of the file - --pid=PID Used with -f, ends after the process with the given PID dies
- -q, --quiet, --silent Never output headers with the given filename
- -s, --sleep-interval=S Used with -f, sleeps S seconds between each iteration
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