成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

測(cè)試過(guò)程中常用的linux命令之【查看文件指定行的內(nèi)容】-創(chuàng)新互聯(lián)

   在開(kāi)展測(cè)試工作的過(guò)程中,通常要接觸到服務(wù)器,對(duì)于linux服務(wù)器,總結(jié)一些常用的命令。

創(chuàng)新互聯(lián)致力于互聯(lián)網(wǎng)網(wǎng)站建設(shè)與網(wǎng)站營(yíng)銷(xiāo),提供成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、網(wǎng)站開(kāi)發(fā)、seo優(yōu)化、網(wǎng)站排名、互聯(lián)網(wǎng)營(yíng)銷(xiāo)、小程序開(kāi)發(fā)、公眾號(hào)商城、等建站開(kāi)發(fā),創(chuàng)新互聯(lián)網(wǎng)站建設(shè)策劃專(zhuān)家,為不同類(lèi)型的客戶(hù)提供良好的互聯(lián)網(wǎng)應(yīng)用定制解決方案,幫助客戶(hù)在新的全球化互聯(lián)網(wǎng)環(huán)境中保持優(yōu)勢(shì)。
  •    準(zhǔn)備工作

    為了能直觀展示命令結(jié)果,使用腳本創(chuàng)建一個(gè)文件,在顯示文件內(nèi)容的同時(shí),也直觀的顯示行號(hào)。

#!/bin/bash

FileName=TestFile.log
touch ./$FileName

i=1
while [ $i -le $1 ]
do
        echo "the line number is $i" >> $FileName
        let "i=$i+1"
done

命令選項(xiàng)示例
head-n,顯示行數(shù)
[root@Durian scripts]# head -n 5 TestFile.log 
the line number is 1
the line number is 2
the line number is 3
the line number is 4
the line number is 5

#顯示文件的前5行

[root@Durian scripts]# head -n -6 TestFile.log 
the line number is 1
the line number is 2
the line number is 3
the line number is 4
the line number is 5
the line number is 6
the line number is 7
the line number is 8
the line number is 9
the line number is 10
the line number is 11
the line number is 12
the line number is 13
the line number is 14

#截去后6行,顯示剩余內(nèi)容


[root@Durian scripts]# head TestFile.log 
the line number is 1
the line number is 2
the line number is 3
the line number is 4
the line number is 5
the line number is 6
the line number is 7
the line number is 8
the line number is 9
the line number is 10

#當(dāng)沒(méi)有選項(xiàng)參數(shù)時(shí),默認(rèn)顯示前10行

-v ,在首行打印文件名稱(chēng)
[root@Durian scripts]# head -n 5 -v TestFile.log 
==> TestFile.log <==
the line number is 1
the line number is 2
the line number is 3
the line number is 4
the line number is 5

#在首行打印文件名稱(chēng)

tail-n,顯示行數(shù)
[root@Durian scripts]# tail -n 4 TestFile.log 
the line number is 17
the line number is 18
the line number is 19
the line number is 20

#查看messages文件的最后4行內(nèi)容


[root@Durian scripts]# tail -n +5 TestFile.log 
the line number is 5
the line number is 6
the line number is 7
the line number is 8
the line number is 9
the line number is 10
the line number is 11
the line number is 12
the line number is 13
the line number is 14
the line number is 15
the line number is 16
the line number is 17
the line number is 18
the line number is 19
the line number is 20

#截去前4行,顯示剩余內(nèi)容


[root@Durian scripts]# tail TestFile.log 
the line number is 11
the line number is 12
the line number is 13
the line number is 14
the line number is 15
the line number is 16
the line number is 17
the line number is 18
the line number is 19
the line number is 20

#當(dāng)沒(méi)有選項(xiàng)參數(shù)時(shí),默認(rèn)顯示最后10行

-f

tail -f /var/log/messages

#當(dāng)文件內(nèi)容有更新時(shí),動(dòng)態(tài)的顯示最新的內(nèi)容

-v ,在首行打印文件名稱(chēng)
[root@Durian scripts]# tail -v -n 3 TestFile.log 
==> TestFile.log <==
the line number is 18
the line number is 19
the line number is 20

#在首行打印文件名稱(chēng)


[root@Durian scripts]# head -n 15 TestFile.log |tail -n 5
the line number is 11
the line number is 12
the line number is 13
the line number is 14
the line number is 15

#查看中間行第11~15行的內(nèi)容

sed-n,與p一起使用
[root@Durian scripts]# sed -n '10p' TestFile.log 
the line number is 10
#查看第10行的內(nèi)容

[root@Durian scripts]# sed -n '11,14p' TestFile.log 
the line number is 11
the line number is 12
the line number is 13
the line number is 14

#查看第11~14行的內(nèi)容

vi
[root@Durian scripts]# vi +12 TestFile.log

#文件打開(kāi)后,光標(biāo)直接定位在第12行

more
[root@Durian scripts]# more -4 TestFile.log 
the line number is 1
the line number is 2
the line number is 3
the line number is 4
--More--(19%)

#顯示前4行


[root@Durian scripts]# more +4 TestFile.log 
the line number is 4
the line number is 5
the line number is 6
the line number is 7
the line number is 8
the line number is 9
the line number is 10
the line number is 11
the line number is 12
the line number is 13
the line number is 14
the line number is 15
the line number is 16
the line number is 17
the line number is 18
the line number is 19
the line number is 20

#截去前3行,顯示剩余內(nèi)容

less
[root@Durian scripts]# less +4 TestFile.lo

#截去前3行,顯示剩余內(nèi)容

分享標(biāo)題:測(cè)試過(guò)程中常用的linux命令之【查看文件指定行的內(nèi)容】-創(chuàng)新互聯(lián)
標(biāo)題網(wǎng)址:http://jinyejixie.com/article46/isieg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊(cè)、定制網(wǎng)站、Google、移動(dòng)網(wǎng)站建設(shè)微信小程序、網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都app開(kāi)發(fā)公司
浦城县| 清徐县| 高阳县| 峨边| 五大连池市| 衢州市| 罗江县| 武定县| 郴州市| 剑阁县| 岳阳市| 乡城县| 莱芜市| 福安市| 黑龙江省| 莱芜市| 迁西县| 迁西县| 凯里市| 内黄县| 民丰县| 麦盖提县| 岳池县| 平陆县| 彭泽县| 许昌县| 库尔勒市| 苏尼特左旗| 涿鹿县| 大庆市| 义马市| 施秉县| 张家界市| 民勤县| 白水县| 绥德县| 陇西县| 裕民县| 德江县| 十堰市| 塔河县|