One, command analysis
Syntax: tail options file address
options:
-f : This parameter is used to monitor File file growth.
-c Number : Read the specified file from the Number byte position
-n Number : Read the specified file from the Number line position.
-m Number : Read the specified file from the Number multi-byte character position. For example, if your file includes Chinese characters, if you specify the -c parameter, it may cause truncation, but using -m will avoid this problem.
-b Number : Read the specified file from the 512-byte block position indicated by Number.
-k Number : Read the specified file from the 1KB block position indicated by Number.
--pid=PID combined with -f: means that the process ID and PID will end after they die
-q, --quiet, --silent: never output the first part of the given file name
-s, --sleep-interval=S combined with -f: means sleep for S seconds at the interval of each repetition
File address : Specify the target file name of the operation
In the above commands, number is involved. If it is not specified, 10 lines are displayed by default. Signs can be used in front of Number to indicate whether the offset is calculated from the top or the tail.
Note: What type of log to view, choose according to options
Two, example
There is nohup.out file in the /home/test/ directory. Now to operate this file, first: cd /home/test/
1. Monitor this file in real time, that is, track the growth of the file named nohup.out
tail -f nohup.out 或者 tail -f /home/test/nohup.out
2. Display the last 10 lines of log
tail nohup.out 或者 tail -n 10 nohup.out
3. From the 20th line to the end of the text
tail +20 nohup.out
4. Display the last 10 characters of the file
tail -c 10 nohup.out
5. Display the last 10 lines of the file in reverse order
tail -r -n 10 nohup.out
Three, experience
View the project log or track the real-time log, which is helpful to follow up the project problems, and also record some of your own study notes.