Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

One of the linux commands commonly used during testing [view the contents of the specified line in the file]

Shulou Source: shulou.com Published: 2022-06-03 03:08:10 10月05日 Update

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

Tags: Content file name remaining command intuitive parameter server work service common procedure test cursor dynamic at the same time example result script line number Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Docker Redmi MariaDB vpn