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. Servlet基本用法二接口和类

    转自:http://www.cnblogs.com/xujian2014/p/4536168.html 一.摘要 本文主要简单介绍开发Servlet需要用到的接口和类. 二.ServletReques ...

  2. 简单的 nginx 多站点配置

    测试环境:基于CentOS6.8 编译安装LNMP(http://www.cnblogs.com/afee666/p/6836161.html) 一 需求 在一个 VPS 主机上配置 web 服务器, ...

  3. sqlserver 中EXEC和sp_executesql使用介绍

    sqlserver 中EXEC和sp_executesql使用介绍 MSSQL为我们提供了两种动态运行SQL语句的命令,各自是EXEC和sp_executesql;通常,sp_executesql则更 ...

  4. 在eclipse中使用Maven建web工程的两种方式

    Eclipse版本:Neon Release (4.6.0) Maven版本:3.3.9 第一种方式: 右键新建maven工程,勾选创建一个简单工程 填入信息,注意打包方式要改为war 点击完成,创建 ...

  5. 创建标题栏,UINavigationBar的使用

    IOS 开发有关界面的东西不仅可以使用代码来编写,也可以使用Interface Builder可视化工具来编写.今天有个朋友问我这两个有什么区别,首先说说IB ,使用它编辑出来的控件其实底层还是调用代 ...

  6. void 指针的转换

    不论什么类型的指针都能够显式转换为void类型,且不会丢失数据.例如以下面程序: #include<stdio.h> int main(void) { short a=5; void *p ...

  7. es6/es7 对象数组的合并拷贝

    方法一: let o1 = { a: 1, b: 2, c: 3 }; let o2 = {...o1, d: 4}; // o2 = { a: 1, b: 2, c: 3, d: 4 } let a ...

  8. cxf + spring + maven 开发webservice

    1.maven 配置 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://ww ...

  9. IIS7设置默认页

    一般用ASP.NET创建的网站默认页都是Default.aspx,不需要设置. 但是如果有网站的起始页不是Default.aspx,就需要在IIS里设置了. IIS7的设置方法和IIS6的不一样: 在 ...

  10. HTML DOM节点的增删改查

    上篇博客中,我们已经初步接触了DOM基础,可是我们学习是为了可以更好地应用,今天我们就来看看DOM节点的增删改查. 无论在哪里,我们想要操作一个东西,总是应该先去获得它.那么我们怎么获得呢? HTML ...