200 ? "200px" : this.width)!important;}
-->

介绍

head和tail是一组想对应的命令,默认分别显示文件的开头和末尾10行记录。

head命令

head命令默认显示头部的前N行

Usage: head [OPTION]... [FILE]...
默认输出前10行
当指定多个文件时,在输出前输出各个文件名
当没有指定文件或指定的文件是“-”说明读取标准输入 Mandatory arguments to long options are mandatory for short options too.
-c, --bytes=[-]K print the first K bytes of each file;
with the leading `-', print all but the last
K bytes of each file 显示头部前多少字节,这里的K是单位的标示,具体的单位参考下面列表,当使用-K时显示除了尾部多少字节外的所有内容
-n, --lines=[-]K print the first K lines instead of the first ;
with the leading `-', print all but the last
K lines of each file显示头部的多少行,默认显示头部10行,例如-n -b代表显示除了尾部512行外的所有行
-q, --quiet, --silent never print headers giving file names当指定多个文件时,出现内容中不输出文件名
-v, --verbose always print headers giving file names
--help display this help and exit
--version output version information and exit K may have a multiplier suffix:
b , kB , K , MB *, M *,
GB **, G **, and so on for T, P, E, Z, Y.

tail命令

tail命令同head命名正好相反,tail默认输出尾部10行

Usage: tail [OPTION]... [FILE]...
默认输出尾部10行
当指定多个文件时,默认在输出内容前显示文件名
当没有指定文件或者指定的文件是“-”时,读取标准输入 Mandatory arguments to long options are mandatory for short options too.对于长选项不可忽略的参数对应短选项也不可忽略
-c, --bytes=K output the last K bytes; alternatively, use -c +K显示尾部的字节数,当使用+k参数时表示从k字节开始显示到末尾,例如-c +1b 显示512字节开始到末尾的内容
to output bytes starting with the Kth of each file
-f, --follow[={name|descriptor}]
output appended data as the file grows;
-f, --follow, and --follow=descriptor are
equivalent追加显示文件最新的内容
-F same as --follow=name --retry等同于使用 -f filename --retry操作
-n, --lines=K output the last K lines, instead of the last ;默认显示输出尾部的10行,当使用+k参数时指从第K行开始显示到末尾,例如-n +6显示第6行到末尾的内容
or use -n +K to output lines starting with the Kth
--max-unchanged-stats=N
with --follow=name, reopen a FILE which has not
changed size after N (default ) iterations
to see if it has been unlinked or renamed
(this is the usual case of rotated log files).
With inotify, this option is rarely useful.
--pid=PID with -f, terminate after process ID, PID dies--指定进程id,可以结合-f参数一起使用,当指定的进程终止时显示也终止
-q, --quiet, --silent never output headers giving file names ###同时显示多个文件时不输出文件名
--retry keep trying to open a file even when it is or当连接的文件突然不可访问时尝试重新连接
becomes inaccessible; useful when following by
name, i.e., with --follow=name
-s, --sleep-interval=N with -f, sleep for approximately N seconds当使用-f参数时可以,使用-s显示间隔
(default 1.0) between iterations.
With inotify and --pid=P, check process P at
least once every N seconds.
-v, --verbose always output headers giving file names
--help display this help and exit
--version output version information and exit If the first character of K (the number of bytes or lines) is a `+',
print beginning with the Kth item from the start of each file, otherwise,
print the last K items in the file. K may have a multiplier suffix:
b , kB , K , MB *, M *,
GB **, G **, and so on for T, P, E, Z, Y.

tail命令参数和head概念差不多,但是要注意二者的+k,-k的各自含义,tail有一个非常有意思的参数是-f参数,使用该参数可以不停的追加显示一个文件最新插入的内容。

1.追加显示文件内容

tail -f /tmp/orzdba_mysql.log 

当文件有新的内容插入进来时它会不停的显示新插入的内容

2.当进程8770终止时,tail也结束

tail -f /tmp/orzdba_mysql.log --pid=

总结

tail -f参数经常会用来监控日志文件的显示,结合实际需要可以充分发挥它的作用

备注:

作者:pursuer.chen

博客:http://www.cnblogs.com/chenmh

本站点所有随笔都是原创,欢迎大家转载;但转载时必须注明文章来源,且在文章开头明显处给明链接。

《欢迎交流讨论》

Linux head和tail命令的更多相关文章

  1. Linux学习之tail命令

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

  2. linux 学习笔记 tail 命令

    #tail -f -n 100 catalina.out 含义:从文件尾部监视catalina.out文件  主要看尾部100行 #tail -f -n 100 catalina.out > n ...

  3. Linux命令学习-tail命令

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

  4. Linux命令详解之—tail命令

    tail命令也是一个非常常用的文件查看类的命令,今天就为大家介绍下Linux tail命令的用法. 更多Linux命令详情请看:Linux命令速查手册 Linux tail命令主要用来从指定点开始将文 ...

  5. 【转载】linux tail命令的使用方法详解

    本文介绍Linux下tail命令的使用方法.linux tail命令用途是依照要求将指定的文件的最后部分输出到标准设备,通常是终端,通俗讲来,就是把某个档案文件的最后几行显示到终端上,假设该档案有更新 ...

  6. linux tail命令的使用方法详解(转)

    本文介绍Linux下tail命令的使用方法.linux tail命令用途是依照要求将指定的文件的最后部分输出到标准设备,通常是终端,通俗讲来,就是把某个档案文件的最后几行显示到终端上,假设该档案有更新 ...

  7. linux tail命令的使用方法详解 (转载)

    本文介绍Linux下tail命令的使用方法.linux tail命令用途是依照要求将指定的文件的最后部分输出到标准设备,通常是终端,通俗讲来,就是把某个档案文件的最后几行显示到终端上,假设该档案有更新 ...

  8. linux tail 命令详解

    linux ---tail命令 linux中tail命令---用于查看文件内容 最基本的是cat.more和less. 1. 如果你只想看文件的前5行,可以使用head命令,如: head -5 /e ...

  9. 【转】Linux tail 命令详解

    Linux tail 命令详解 http://www.2cto.com/os/201111/110143.html

随机推荐

  1. jdk1.8下载安装

    jdk8环境变量 jdk8图解安装 java8安装   1 2 3 4 5 6 7 分步阅读 JDK8 是JDK的最新版本,加入了很多新特性,如果我们要使用,需要下载安装: JDK8在windows ...

  2. SAAS在中国市场的发展前景

    发展现状 2008年1-7月软件行业实现收入4199.1亿元,同比增长32.4%.2008年第一季度,业务管理软件市场总量达16.31亿元,同比增长17.8%.面对成本的上升,企业选择了向信息化要效率 ...

  3. ilspy导致c# dll代码被窃取

    不得不放弃.net框架的任何开发!!!微软现在太蛋疼了!!! 不得不放弃.net框架的任何开发!!!微软现在太蛋疼了!!! 不得不放弃.net框架的任何开发!!!微软现在太蛋疼了!!! 不得不放弃.n ...

  4. C#中的using和yield return混合使用

    最近写代码为了为了省事儿用了几个yield return,因为我不想New一个List<T>或者T[]对象再往里放元素,就直接返回IEnumerable<T>了.我的代码里还有 ...

  5. html input的file文件输入框onchange事件触发一次失效解决方法

    最近在做一个图片上传的功能,出现提交一次后,file输入框的change事件无法再次触发的bug,就是说提交一次后必须刷新才能再次提交,这就坑了~ 于是想办法解决它~ 在网上找了一些资料,找到这几种方 ...

  6. 计算机网路之动态NAT配置

    配置路由端口的ip地址与打开(省略) 配置路由协议 router eigrp 100 network 211.1.1.0(网络号) 0.0.0.255(通配子掩) network 192.168.1. ...

  7. 安卓奇葩问题之.so库加载不了

    真是哔了狗了. 今天突然遇到一个问题:之前用第三方的密码控件,给了一个.so库文件.然后我就放在了/jniLibs/armeabi目录下. 运行,一切都很OK. 然后重点来了.N天之后的今天,突然打包 ...

  8. RestSharp简单扩展

    using RestSharp; using RestSharp.Deserializers; using RestSharp.Serializers; using System; using Sys ...

  9. Java和C#语法对比

    Java 有静态导入,既可以导入静态方法和字段. .NET没有 Java里package和文件夹对应关系是强制的,要改都改.而C#中namespace和文件夹可以不对应,C# 更喜欢在一个projec ...

  10. Spring 学习笔记 7. 尚硅谷_佟刚_Spring_Bean 的作用域

    1,理论 •在 Spring 中, 可以在 <bean> 元素的 scope 属性里设置 Bean 的作用域. •默认情况下, Spring 只为每个在 IOC 容器里声明的 Bean 创 ...