One of the linux commands commonly used during testing [view the contents of the specified line in the file]
In the process of testing, you usually have to contact the server, for the linux server, summarize some commonly used commands.
Preparatory work
In order to visually display the results of the command, use a script to create a file that displays the contents of the file as well as the line number.
#! / bin/bashFileName=TestFile.logtouch. / $FileNamei=1while [$I-le $1] do echo "the line number is $I" > > $FileName let "i=$i+1" done
Command option example head-n, showing the number of lines [root@Durian scripts] # head-n 5 TestFile.log the line number is 1the line number is 2the line number is 3the line number is 4the line number is 5
# display the first 5 lines of the file
[root@Durian scripts] # head-n-6 TestFile.log the line number is 1the line number is 2the line number is 3the line number is 4the line number is 5the line number is 6the line number is 7the line number is 8the line number is 9the line number is 10the line number is 11the line number is 12the line number is 13the line number is 14
# truncate the last 6 lines to show the rest
[root@Durian scripts] # head TestFile.log the line number is 1the line number is 2the line number is 3the line number is 4the line number is 5the line number is 6the line number is 7the line number is 8the line number is 9the line number is 10
# when there is no option parameter, the first 10 lines are displayed by default
-v, print the file name [root@Durian scripts] # head-n 5-v TestFile.log = = > TestFile.log TestFile.log on the first line