Linux tail command
The tail command can be used to view file contents, and it has a commonly used parameter-fIt is often used to check log files that are changing.
tail -f filenameIt will display the tail content of the filename file on the screen and keep refreshing. As long as filename is updated, you can see the latest file content.
If you need to view the beginning of the file, use the commandhead。
Command format:
tail [参数] [文件]
Parameters:
- -f Loop reading
- -q Do not display processing information
- -v Display detailed processing information
- -c<number> Display the number of bytes
- -n<number of lines> Display the last n lines of the file
- --pid=PID Used together with -f, means to end after the process ID, PID, dies.
- -q, --quiet, --silent Never output headers giving file names
- -s, --sleep-interval=S Used together with -f, means to sleep for S seconds in each repetition interval
Examples
To display the last 10 lines of the notes.log file, 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. When some lines are added to the notes.log file, the tail command will continue to display those lines. The display continues until you press the (Ctrl-C) key combination to stop it.
Display the contents of the file notes.log from line 20 to the end of the file:
tail -n +20 notes.log
Display the last 10 characters of the file notes.log:
tail -c 10 notes.logOther Extensions
Linux Command Encyclopedia