每天一个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]#
每天一个Linux命令(15)tail命令的更多相关文章
- 每天一个linux命令(15):tail命令
1.命令简介 tail (tail) 用来显示档案的结尾(默认为10行)至标准输出中.若指定了多于一个文件,程序会在每段输出的开始添加相应文件名作为头.如果不指定文件或文件为"-" ...
- 每日linux命令学习-head命令和tail命令
本节主要学习了linux文件浏览的相关命令,包括cat.less.more.read.tail等,由于本人经常使用cat.less.more命令,已经较为熟悉,所以本节重点学习head命令和tail命 ...
- Linux命令学习-tail命令
Linux中,tail命令的全称就是tail,主要用于监控日志文件. 对于一个正在运行应用来说,其对应的log日志文件肯定是在不断的更新,此时,便可通过tail命令来动态显示日志文件的内容.假设当前目 ...
- grep命令和tail命令
写在前面的话: 最近参与了新项目开发,周期短,与自己负责的主要业务对接.业务复杂,时常出现bug,然额对于菜鸟的我,更是无从下手.其实最好的帮助就是 学会查看日志,关键是之前查看日志真是太少了,菜鸟一 ...
- 每天一个Linux命令(05):tail命令
tail命令用于输入文件中的尾部内容.tail命令默认在屏幕上显示指定文件的末尾10行.如果给定的文件不止一个,则在显示的每个文件前面加一个文件名标题.如果没有指定文件或者文件名为"-&qu ...
- linux 命令——15 tail (转)
tail 命令从指定点开始将文件写到标准输出.使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail -f filename会把filename里最尾部的内容显示在屏幕上,并且不但刷新, ...
- Linux head和tail命令
200 ? "200px" : this.width)!important;} --> 介绍 head和tail是一组想对应的命令,默认分别显示文件的开头和末尾10行记录. ...
- Linux学习之tail命令
tail 命令从指定点开始将文件写到标准输出.使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail -f filename会把filename里最尾部的内容显示在屏幕上,并且不但刷新, ...
- linux常用命令:tail 命令
tail 命令从指定点开始将文件写到标准输出.使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail -f filename会把filename里最尾部的内容显示在屏幕上,并且不但刷新, ...
- 【Linux 命令】- tail命令
linux tail命令用途是依照要求将指定的文件的最后部分输出到标准设备,通常是终端,通俗讲来,就是把某个档案文件的最后几行显示到终端上,假设该档案有更新,tail会自己主动刷新,确保你看到最新的档 ...
随机推荐
- 分类--ROC 和曲线下面积
ROC 曲线(接收者操作特征曲线)是一种显示分类模型在所有分类阈值下的效果的图表.该曲线绘制了以下两个参数: 真正例率 假正例率 真正例率 (TPR) 是召回率的同义词,因此定义如下: $$TPR = ...
- SQL Server统计信息:问题和解决方式
在网上看到一篇介绍使用统计信息出现的问题已经解决方式,感觉写的很全面. 在自己看的过程中顺便做了翻译. 因为本人英文水平有限,可能中间有一些错误. 假设有哪里有问题欢迎大家批评指正.建议英文好的直接看 ...
- web网页按钮如何制作
1:用矩形形状工具画一个矩形 2 : 加描边 3:三键+N新建图层 前景色变成白色,白色到透明的渐变,选择径向渐变. 4:为了使自然,按住ALT键,使渐变扩大,和矩形保持一直,之后向上调整一些. 5: ...
- Oracle Golden Gate基本配置
>> from zhuhaiqing.info [oracle@localhost ogg]$ cat ~/.bash_profile GG_HOME=/opt/oggPATH=$PATH ...
- 开发中可能会用到的几个小tip----QT, pycharm, android, 等
QT: 如果是在windows下开发的话,添加外部库,外部包含头文件路径的时候,要注意用相对路径,或者在项目上右键添加外部库的路径或者头文件路径,否则,会卡在这里开始怀疑人生... 如果是在linux ...
- 启动 ./spark-shell 命令报错
当使用./spark-shell 命令报错 Caused by: ERROR XJ040: Failed to start database @476fde05, see the next excep ...
- Java中HashTable和HashMap的区别
在Java中,HashTable和HashMap都是哈希表,那么它们有什么区别呢? 1.它们所继承的类不一样. HashTable和HashMap都实现了Map接口,但是它们所继承的类时不同的.H ...
- 昂贵的聘礼 - poj 1062 (Dijkstra+枚举)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 39976 Accepted: 11596 Description 年 ...
- php 生成下载连接
public function showdownload(){ $file_url=$_GET['url']; $new_name='激活码'; if(!isset($file_url)||trim( ...
- 002android初级篇之ViewPager及PagerSlidingTabStrip listview的使用
002android初级篇之ViewPager及PagerSlidingTabStrip listview的使用 ViewPager ViewPager类直接继承了ViewGroup类,所有它是一个容 ...