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. 安装Linux centos 时编辑选项

    将第上一步选择编辑之后出来的文字修改为:>vmlinuz initrd=initrd.img linux dd quiet 这里注意了:网上很多文章都说这一步改成“>vmlinuz ini ...

  2. 【Lucene】Apache Lucene全文检索引擎架构之入门实战1

    Lucene是一套用于全文检索和搜寻的开源程式库,由Apache软件基金会支持和提供.Lucene提供了一个简单却强大的应用程式接口,能够做全文索引和搜寻.在Java开发环境里Lucene是一个成熟的 ...

  3. ie8下面版本号(包含ie8)的浏览器不支持html5标签属性解决方式(Modernizr 2.6.2插件的使用)

    我这边申明下:我写这篇日志主要是想然ie8可以支持html5的个别标签闭合,并不能让ie全然支持html5.我之前写的可能会误导非常多同学.希望大家能明确. 今天脑抽想用html5标签设计一个网页.我 ...

  4. yarn-1.12.3.msi 下载地址 百度网盘

    yarn-1.12.3.msi 下载地址 百度网盘 链接:https://pan.baidu.com/s/1-JEO1as0Jtp1a1pAqW-mzg 提取码:lbz0

  5. Nginx访问日志和错误日志的拆分(Logstash)

    >> from zhuhaiqing.info input { file { type =>> "nginx-access" path =>> ...

  6. 让Category支持添加属性与成员变量【转载】

    Category是Objective-C中常用的语法特性,通过它可以很方便的为已有的类来添加函数.但是Category不允许为已有的类添加新的属性或者成员变量.     一种常见的办法是通过runti ...

  7. 第一次接触solr的过程记录

    1.以solr-4.6.0.tgz为例进行学习 2.第一步,看的是 tutorial.html(位于solr-4.6.0/docs目录),默认solr以jetty作为servlet容器 3.但是,如果 ...

  8. Apache中KeepAlive 配置

    引子 先来分析一个Yslow 测试的一个页面的前端性能. 这里所有的请求是指http请求,对于一个请求各个阶段的划分,阻挡->域名解析->建立连接->发送请求->等待响应-&g ...

  9. Dockerfile安装KOD可道云

    [root@docker01 base2]# cat Dockerfile FROM centos:6.8 RUN yum install openssh-server -y RUN /etc/ini ...

  10. 【Github】之突然访问不了Github地址

    访问Github突然上不去了 解决办法: 一.修改hosts 1.打开Dns检测|Dns查询 - 站长工具2.在检测输入栏中输入http://github.com官网3.把检测列表里的TTL值最小的I ...