每天一个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会自己主动刷新,确保你看到最新的档 ...
随机推荐
- 51单片机 | 模拟PWM调制控制实验
———————————————————————————————————————————— PWM(脉冲宽度调制) 对模拟信号电平进行数字编码的方法 - - - - - - - - - - - - - ...
- 【Mysql】 你会用 information_schema吗?
示例 select * from information_schema.views 其中的views可以替换成以下的字段,以下未列举的一般的数据库操作工具,在information_schema后输入 ...
- C# const和static readonly区别
[转]C# const和static readonly区别 以前只是知道Const和static readonlyd的区别在于const的值是在编译期间确定的,而static readonly是在运行 ...
- struts2中怎样处理404?
眼下在做一个网络应用程序,struts2 + spring + hibernate,server是tomcat.希望用户在IE地址栏乱敲的时候.所敲入的全部没有定义的URL都能被程序捕捉到,然后转到一 ...
- python测试网页是否能正常登陆
#!/usr/bin/python #encoding:utf-8 ##实现网页的登陆检查 import HTMLParser import urlparse import cookielib imp ...
- GDBus
1. https://en.wikipedia.org/wiki/D-Bus In computing, D-Bus (for "Desktop Bus"[4]), a softw ...
- MIC的异步传输
关于signal和wait,属于异步传输的语法,即CPU端无需等待offload语句返回,即可异步运行下面的代码.一般用于启动MIC代码段后,并发执行CPU代码,达到同步执行的目的.另外一种用法是使用 ...
- 并行归并排序——MPI
并行归并排序在程序开始时,会将n/comm_comm个键值分配给每个进程,程序结束时,所有的键值会按顺序存储在进程0中.为了做到这点,它使用了树形结构通信模式.当进程接收到另一个进程的键值时,它将该键 ...
- sublime无法使用package Control解决办法。
http://blog.csdn.net/freshlover/article/details/44261229
- spring boot集成activemq
spring boot集成activemq 转自:https://blog.csdn.net/maiyikai/article/details/77199300