Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 244

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report