在linux中使用head命令和tail命令查看文件中的指定行
2016-09-15 01:18
573 查看
使用head命令和tail命令显示指定的行:
head
-n, –lines=[-]K
print the first K lines instead of the first 10; with the leading
‘-’, print all but the last K lines of each file
tail
-n, –lines=K
output the last K lines, instead of the last 10; or use -n +K to
output lines starting with the Kth
[root@localhost etc]# pwd
/etc
[root@localhost etc]# cat yum.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
//此处是一空行
# This is the default, if you make this bigger yum won’t see if the metadata
# is newer on the remote and so you’ll “gain” the bandwidth of not having to
# download the new metadata and “pay” for it by yum not having correct
# information.
# It is esp. important, to have correct metadata, for distributions like
# Fedora which don’t keep old packages around. If you don’t like this checking
# interupting your command line usage, it’s much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m
//此处是一空行
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
[root@localhost etc]# cat yum.conf |wc -l
23
yum.conf文件共有23行
[root@localhost etc]# head yum.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@localhost etc]# head -n 2 yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
显示前2行
[root@localhost etc]# head -n -20 yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
显示除最后20行以外的所有行
[root@localhost etc]# tail yum.conf
# download the new metadata and “pay” for it by yum not having correct
# information.
# It is esp. important, to have correct metadata, for distributions like
# Fedora which don’t keep old packages around. If you don’t like this checking
# interupting your command line usage, it’s much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m
//此处是一空行
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
显示最后10行,这是默认值
[root@localhost etc]# tail -n 2 yum.conf
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
显示最后2行
[root@localhost etc]# tail -n +21 yum.conf
//此处是一空行
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
从第21行开始显示后面的所有行,即第21行到第23行
显示第11行到第20行(总共23行):
从第11行开始显示,但不包括最后3行
[huage@localhost etc]$ head -n -3 yum.conf |tail -n +11
显示前20行,但从第11行开始
[huage@localhost etc]$ head -n 20 yum.conf |tail -n +11
显示除最后3行以外的所有行,但只显示最后10行
[huage@localhost etc]$ head -n -3 yum.conf |tail -n 10
显示前20行中的后10行
[huage@localhost etc]$ head -n 20 yum.conf |tail -n 10
从第11行开始显示,但只显示前10行
[huage@localhost etc]$ tail -n +11 yum.conf |head -n 10
从第11行开始显示,但不包括最后3行
[huage@localhost etc]$ tail -n +11 yum.conf |head -n -3
显示最后13行中的前10行
[huage@localhost etc]$ tail -n 13 yum.conf |head -n 10
显示最后13行中除末尾的3行以外的前10行
[huage@localhost etc]$ tail -n 13 yum.conf |head -n -3
原文:http://www.androidstar.cn/在linux中使用head命令和tail命令查看文件中的指定行/
head
-n, –lines=[-]K
print the first K lines instead of the first 10; with the leading
‘-’, print all but the last K lines of each file
tail
-n, –lines=K
output the last K lines, instead of the last 10; or use -n +K to
output lines starting with the Kth
[root@localhost etc]# pwd
/etc
[root@localhost etc]# cat yum.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
//此处是一空行
# This is the default, if you make this bigger yum won’t see if the metadata
# is newer on the remote and so you’ll “gain” the bandwidth of not having to
# download the new metadata and “pay” for it by yum not having correct
# information.
# It is esp. important, to have correct metadata, for distributions like
# Fedora which don’t keep old packages around. If you don’t like this checking
# interupting your command line usage, it’s much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m
//此处是一空行
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
[root@localhost etc]# cat yum.conf |wc -l
23
yum.conf文件共有23行
[root@localhost etc]# head yum.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@localhost etc]# head -n 2 yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
显示前2行
[root@localhost etc]# head -n -20 yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
显示除最后20行以外的所有行
[root@localhost etc]# tail yum.conf
# download the new metadata and “pay” for it by yum not having correct
# information.
# It is esp. important, to have correct metadata, for distributions like
# Fedora which don’t keep old packages around. If you don’t like this checking
# interupting your command line usage, it’s much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m
//此处是一空行
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
显示最后10行,这是默认值
[root@localhost etc]# tail -n 2 yum.conf
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
显示最后2行
[root@localhost etc]# tail -n +21 yum.conf
//此处是一空行
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
从第21行开始显示后面的所有行,即第21行到第23行
显示第11行到第20行(总共23行):
从第11行开始显示,但不包括最后3行
[huage@localhost etc]$ head -n -3 yum.conf |tail -n +11
显示前20行,但从第11行开始
[huage@localhost etc]$ head -n 20 yum.conf |tail -n +11
显示除最后3行以外的所有行,但只显示最后10行
[huage@localhost etc]$ head -n -3 yum.conf |tail -n 10
显示前20行中的后10行
[huage@localhost etc]$ head -n 20 yum.conf |tail -n 10
从第11行开始显示,但只显示前10行
[huage@localhost etc]$ tail -n +11 yum.conf |head -n 10
从第11行开始显示,但不包括最后3行
[huage@localhost etc]$ tail -n +11 yum.conf |head -n -3
显示最后13行中的前10行
[huage@localhost etc]$ tail -n 13 yum.conf |head -n 10
显示最后13行中除末尾的3行以外的前10行
[huage@localhost etc]$ tail -n 13 yum.conf |head -n -3
原文:http://www.androidstar.cn/在linux中使用head命令和tail命令查看文件中的指定行/
相关文章推荐
- 在linux中使用head命令和tail命令查看文件中的指定行
- linux中使用head命令和tail命令查看文件中的指定行
- Linux系统中使用head命令和tail命令查看指定文件中的指定行到某行命令
- linux 浏览查看文件more,less,head,tail,cat,tac,od,nl命令使用简介
- linux用于查看文件内容 tail、cat、more、less、head 、sed 命令
- Linux下查看文件常用命令—cat,more,less,head,tail,od,file
- linux查看日志文件内容命令tail、cat、tac、head、echo
- Linux中查看文本文件内容命令cat/tac/nl/more/less/head/tail/vi总结
- linux查看日志文件内容命令sed、cat、tac、more、less、head、tail、echo 1、按时间查询 sed -n '/2017-09-20 14:00:/,/2017-
- Linux下查看文件常用命令-cat,more,less,head,tail
- linux常用命令-查看文件内容(tail/head/cat/more/less)
- linux查看日志文件内容命令tail、cat、tac、head、echo
- Linux中查看文本文件内容命令cat/tac/nl/more/less/head/tail/vi总结
- 【Linux】linux查看日志文件内容命令tail、cat、tac、head、echo
- linux查看文件命令 head sed tail
- linux用于查看文件内容 tail、cat、more、less、head 、sed 命令
- Linux基本操作命令之文件查看cat more less tail head
- Linux中查看文本文件内容命令cat/tac/nl/more/less/head/tail/vi总结
- linux查看日志文件内容命令tail、cat、tac、head、echo
- Linux查看文件常用命令学习--cat\more\head\tail