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命令的更多相关文章

  1. 每天一个linux命令(15):tail命令

    1.命令简介 tail (tail) 用来显示档案的结尾(默认为10行)至标准输出中.若指定了多于一个文件,程序会在每段输出的开始添加相应文件名作为头.如果不指定文件或文件为"-" ...

  2. 每日linux命令学习-head命令和tail命令

    本节主要学习了linux文件浏览的相关命令,包括cat.less.more.read.tail等,由于本人经常使用cat.less.more命令,已经较为熟悉,所以本节重点学习head命令和tail命 ...

  3. Linux命令学习-tail命令

    Linux中,tail命令的全称就是tail,主要用于监控日志文件. 对于一个正在运行应用来说,其对应的log日志文件肯定是在不断的更新,此时,便可通过tail命令来动态显示日志文件的内容.假设当前目 ...

  4. grep命令和tail命令

    写在前面的话: 最近参与了新项目开发,周期短,与自己负责的主要业务对接.业务复杂,时常出现bug,然额对于菜鸟的我,更是无从下手.其实最好的帮助就是 学会查看日志,关键是之前查看日志真是太少了,菜鸟一 ...

  5. 每天一个Linux命令(05):tail命令

    tail命令用于输入文件中的尾部内容.tail命令默认在屏幕上显示指定文件的末尾10行.如果给定的文件不止一个,则在显示的每个文件前面加一个文件名标题.如果没有指定文件或者文件名为"-&qu ...

  6. linux 命令——15 tail (转)

    tail 命令从指定点开始将文件写到标准输出.使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail -f filename会把filename里最尾部的内容显示在屏幕上,并且不但刷新, ...

  7. Linux head和tail命令

    200 ? "200px" : this.width)!important;} --> 介绍 head和tail是一组想对应的命令,默认分别显示文件的开头和末尾10行记录. ...

  8. Linux学习之tail命令

    tail 命令从指定点开始将文件写到标准输出.使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail -f filename会把filename里最尾部的内容显示在屏幕上,并且不但刷新, ...

  9. linux常用命令:tail 命令

    tail 命令从指定点开始将文件写到标准输出.使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail -f filename会把filename里最尾部的内容显示在屏幕上,并且不但刷新, ...

  10. 【Linux 命令】- tail命令

    linux tail命令用途是依照要求将指定的文件的最后部分输出到标准设备,通常是终端,通俗讲来,就是把某个档案文件的最后几行显示到终端上,假设该档案有更新,tail会自己主动刷新,确保你看到最新的档 ...

随机推荐

  1. 如何为Apache JMeter开发插件(二)—第一个JMeter插件

    文章内容转载于:http://lib.csdn.net/article/softwaretest/25700,并且加上个人一些截图 本篇将开启为JMeter开发插件之旅,我们选择以Function(函 ...

  2. 运行./cpp.sh,显示command not found

    首先运行ls -l 查看这个文件的属性是否可执行drwxrwxrwx对当前用户必须具有可执行权限(即含有x符号)如果没有可以运行chmod 777 cpp.sh 添加可执行权限

  3. svn client命令

    经常使用svn命令说明 1.从SVN仓库中检索出代码到工作拷贝: # svn checkout https://svn.sinaapp.com/appname [workcopy] 当中workcop ...

  4. thread.join() 方法存在的必要性是什么?

    好久远的问题,为什么关注这个问题的人这么少? 或许是用到这个功能的情形比较少吧. 1.等待处理结果 为什么要用join()方法在很多情况下,主线程生成并起动了子线程,如果子线程里要进行大量的耗时的运算 ...

  5. 《HTML 5网页开发实例具体解释》样章、内容简单介绍、前言

    http://spu.jd.com/1167757597.html http://product.dangdang.com/23484942.html 样章 http://download.csdn. ...

  6. 【COCOS2DX-LUA 脚本开发之一】在Cocos2dX游戏中使用Lua脚本进行游戏开发(基础篇)并介绍脚本在游戏中详细用途!

    [COCOS2DX-LUA 脚本开发之一]在Cocos2dX游戏中使用Lua脚本进行游戏开发(基础篇)并介绍脚本在游戏中详细用途! 分类: [Cocos2dx Lua 脚本开发 ] 2012-04-1 ...

  7. apache占用内存高解决办法

    我用512M的vps,访问量不大,但内存占用很大,甚至宕机. 我用top,然后shitf+m发现,httpd占用内存极大.经过网上找资料设置后,用过一段时间终于没再出现内存问题了. 首先查找配置文件的 ...

  8. ubuntu 16.04查询文件安装目录

    dpkg -L filename dpkg -l | grep filename whereis filename find / -name filename

  9. Memcached 常用的方法

    Memcache常用方法 Memcache::add — 添加一个值,如果已经存在,则返回false Memcache::addServer — 添加一个可供使用的服务器地址 Memcache::cl ...

  10. Android Handler警告,SimpleDateFormat警告

    1:Handler// This Handler class should be static or leaks might occur: IncomingHandler    @SuppressLi ...