每天一个Linux命令(15)tail命令
tail命令用于输入文件中的尾部内容。tail命令默认在屏幕上显示指定文件的末尾10行。
如果给定的文件不止一个,则在显示的每个文件前面加一个文件名标题。
(1)用法:
用法: tail [必要参数] [选择参数] [文件]
如果没有指定文件或者文件名为“-”,则读取标准输入。
(2)功能:
功能: 输出文件的末尾部分
(3)选项参数:
1) -n <k行数> 显示文件末尾k行内容
2) -c <k字节数> 显示文件末尾k个字节数
3) -f 循环读取
4) -q 不显示处理信息
5) -v 显示详细的处理信息
(4)实例:
1)[root@localhost Documents]# tail -n 5 ./tail_text 查看文件后5行的内容
[root@localhost Documents]# cat tail_text
> the first line!
> the second line!
> the third line!
> the forth line!
> the fifth line!
> the sixth line!
> o7 the seventh line!
> the eighth line!
> the nineth line!
> the tenth line!
> the eleven line!
> the twelve line!
[root@localhost Documents]# tail -n ./tail_text
> the eighth line!
> the nineth line!
> the tenth line!
> the eleven line!
> the twelve line!
等价于tail -5 text_tail 查看后5行的内容
[root@localhost Documents]# tail - tail_text
> the eighth line!
> the nineth line!
> the tenth line!
> the eleven line!
> the twelve line!
2)[root@localhost Documents]# tail -n +5 tail_text 从第5行开始显示
[root@localhost Documents]# tail -n + tail_text
> the fifth line!
> the sixth line!
> o7 the seventh line!
> the eighth line!
> the nineth line!
> the tenth line!
> the eleven line!
> the twelve line!
3)[root@localhost Documents]# head -n -5 tail_text与[root@localhost Documents]# tail -n -5 tail_text
[root@localhost Documents]# head -n tail_text //显示文件前5行的内容
> the first line!
> the second line!
> the third line!
> the forth line!
> the fifth line!
[root@localhost Documents]# head -n - tail_text //除了文件后五行全部显示
> the first line!
> the second line!
> the third line!
> the forth line!
> the fifth line!
> the sixth line!
> o7 the seventh line! //head命令的-n参数,当后面的整数为正为负是有区别的
[root@localhost Documents]# tail -n tail_text //tail命令的-n参数,当后面的整数为正为负是一样的
> the eighth line!
> the nineth line!
> the tenth line!
> the eleven line!
> the twelve line!
[root@localhost Documents]# tail -n - tail_text //都是显示末尾的整数的绝对值行
> the eighth line!
> the nineth line!
> the tenth line!
> the eleven line!
> the twelve line!
4)[root@localhost Documents]# tail -c 30 tail_text 显示末尾的字节数
[root@localhost Documents]# tail -c tail_text
n line!
> the twelve line!
[root@localhost Documents]# tail -c - tail_text
n line!
> the twelve line!
[root@localhost Documents]# head -c tail_text
> the first line!
> the [root@localhost Documents]# head -c - tail_text
> the first line!
> the second line!
> the third line!
> the forth line!
> the fifth line!
> the sixth line!
> o7 the seventh line!
> the eighth line!
> the nineth line!
> the tenth line!
> the eleve[root@localhost Documents]#
5)[root@localhost Documents]# tail -f tail_text 循环读取内容输出到标准输出
[root@localhost Documents]# tail -f tail_text //默认是后10行
> the third line!
> the forth line!
> the fifth line!
> the sixth line!
> o7 the seventh line!
> the eighth line!
> the nineth line!
> the tenth line!
> the eleven line!
> the twelve line!
^C
[root@localhost Documents]# tail -f -n tail_text //也可以自己指定
> the first line!
> the second line!
> the third line!
> the forth line!
> the fifth line!
> the sixth line!
> o7 the seventh line!
> the eighth line!
> the nineth line!
> the tenth line!
> the eleven line!
> the twelve line!
^Z
[]+ 已停止 tail -f -n tail_text
[root@localhost Documents]# tail -f -n tail_text
> the sixth line!
> o7 the seventh line!
> the eighth line!
> the nineth line!
> the tenth line!
> the eleven line!
> the twelve line!
当然,也可以把信息输入到文件中:
[root@localhost Documents]# tail -f tail_text>tempory
^Z
[]+ 已停止 tail -f tail_text > tempory
[root@localhost Documents]# cat tempory
> the third line!
> the forth line!
> the fifth line!
> the sixth line!
> o7 the seventh line!
> the eighth line!
> the nineth line!
> the tenth line!
> the eleven line!
> the twelve line!
6)[root@localhost Documents]# tail -n +5 tail_text与[root@localhost Documents]# tail -n 5 tail_text
[root@localhost Documents]# tail -n + tail_text
> the fifth line!
> the sixth line!
> o7 the seventh line!
> the eighth line!
> the nineth line!
> the tenth line!
> the eleven line!
> the twelve line!
[root@localhost Documents]# tail -n tail_text
> the eighth line!
> the nineth line!
> the tenth line!
> the eleven line!
> the twelve line!
[root@localhost Documents]# head -n + tail_text
> the first line!
> the second line!
> the third line!
> the forth line!
> the fifth line!
[root@localhost Documents]# head -n tail_text
> the first line!
> the second line!
> the third line!
> the forth line!
> the fifth line!
7)[root@localhost Documents]# tail -n +10 tail_text |head -n -2
[root@localhost Documents]# tail -n + tail_text //从第10行显示到尾部
> the tenth line!
> the eleven line!
> the twelve line!
[root@localhost Documents]# head -n - tail_text //除了末尾两行之外前面的都显示
> the first line!
> the second line!
> the third line!
> the forth line!
> the fifth line!
> the sixth line!
> o7 the seventh line!
> the eighth line!
> the nineth line!
> the tenth line!
[root@localhost Documents]# tail -n + tail_text |head -n -2 //综合起来,用管道命令就是后一个命令处理前面的结果,因此达到只显示第10行的效果
> the tenth line!
[root@localhost Documents]#
最新文章
- 外网访问原理分析 - 每天5分钟玩转 OpenStack(105)
- 初次体验VS2015正式版,安装详细过程。
- UIButton 内部介绍
- C#中值类型和引用类型
- Java-maven异常-cannot be cast to javax.servlet.Filter 报错, 原因servlet-api.jar冲突
- matlab练习程序(图像球面化)
- SmartWiki开发日志之环境配置和系统安装
- 服务器遭受 ssh 攻击
- Python从菜鸟到高手(8):print函数、赋值与代码块
- 什么是IO多路复用
- bzoj 4007
- C#完美任意设置webBrowser框架默认的IE内核版本
- NPOI 导入为table 处理excel 格式问题
- [UE4]Format Text
- Linux下识别所有Android设备的方法
- hdu2602 Bone Collector(01背包) 2016-05-24 15:37 57人阅读 评论(0) 收藏
- 深入理解ajax系列第二篇
- java下执行mongodb
- 【bzoj2763】[JLOI2011]飞行路线 分层图最短路
- Linux su命令参数及用法详解--Linux切换用户命令