使用head命令和tail命令显示指定的行:
head
-n,–lines=[-]K
printthefirstKlinesinsteadofthefirst10;withtheleading
‘-’,printallbutthelastKlinesofeachfile
tail
-n,–lines=K
outputthelastKlines,insteadofthelast10;oruse-n+Kto
outputlinesstartingwiththeKth
[root@localhostetc]#pwd
/etc
[root@localhostetc]#catyum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=3
//此处是一空行
#Thisisthedefault,ifyoumakethisbiggeryumwon’tseeifthemetadata
#isnewerontheremoteandsoyou’ll"gain"thebandwidthofnothavingto
#downloadthenewmetadataand"pay"foritbyyumnothavingcorrect
#information.
#Itisesp.important,tohavecorrectmetadata,fordistributionslike
#Fedorawhichdon’tkeepoldpackagesaround.Ifyoudon’tlikethischecking
#interuptingyourcommandlineusage,it’smuchbettertohavesomething
#manuallycheckthemetadataonceanhour(yum-updatesdwilldothis).
#metadata_expire=90m
//此处是一空行
#PUTYOURREPOSHEREORINseparatefilesnamedfile.repo
#in/etc/yum.repos.d
[root@localhostetc]#catyum.conf|wc-l
23
yum.conf文件共有23行
[root@localhostetc]#headyum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=3
显示前10行,这个是默认值
[root@localhostetc]#head-n2yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
显示前2行
[root@localhostetc]#head-n-20yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
显示除最后20行以外的所有行
[root@localhostetc]#tailyum.conf
#downloadthenewmetadataand"pay"foritbyyumnothavingcorrect
#information.
#Itisesp.important,tohavecorrectmetadata,fordistributionslike
#Fedorawhichdon’tkeepoldpackagesaround.Ifyoudon’tlikethischecking
#interuptingyourcommandlineusage,it’smuchbettertohavesomething
#manuallycheckthemetadataonceanhour(yum-updatesdwilldothis).
#metadata_expire=90m
//此处是一空行
#PUTYOURREPOSHEREORINseparatefilesnamedfile.repo
#in/etc/yum.repos.d
显示最后10行,这是默认值
[root@localhostetc]#tail-n2yum.conf
#PUTYOURREPOSHEREORINseparatefilesnamedfile.repo
#in/etc/yum.repos.d
显示最后2行
[root@localhostetc]#tail-n+21yum.conf
//此处是一空行
#PUTYOURREPOSHEREORINseparatefilesnamedfile.repo
#in/etc/yum.repos.d
从第21行开始显示后面的所有行,即第21行到第23行
显示第11行到第20行(总共23行):
从第11行开始显示,但不包括最后3行
[huage@localhostetc]$head-n-3yum.conf|tail-n+11
显示前20行,但从第11行开始
[huage@localhostetc]$head-n20yum.conf|tail-n+11
显示除最后3行以外的所有行,但只显示最后10行
[huage@localhostetc]$head-n-3yum.conf|tail-n10
显示前20行中的后10行
[huage@localhostetc]$head-n20yum.conf|tail-n10
从第11行开始显示,但只显示前10行
[huage@localhostetc]$tail-n+11yum.conf|head-n10
从第11行开始显示,但不包括最后3行
[huage@localhostetc]$tail-n+11yum.conf|head-n-3
显示最后13行中的前10行
[huage@localhostetc]$tail-n13yum.conf|head-n10
显示最后13行中除末尾的3行以外的前10行
[huage@localhostetc]$tail-n13yum.conf|head-n-3
然后拍一些美得想哭的照片,留给老年的自己。