head命令用于显示文件的开头的内容。在默认情况下,head命令显示文件的头10行内容。

tail命令用于显示文件的结尾的内容。在默认情况下,taild命令显示文件的后10行内容。

head常见命令参数

  -c, --bytes=[-]K         print the first K bytes of each file;
with the leading `-', print all but the last
K bytes of each file
-n, --lines=[-]K print the first K lines instead of the first 10;
with the leading `-', print all but the last
K lines of each file
-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

tail场景命令

 -c, --bytes=K            output the last K bytes; alternatively, use -c +K
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
-n, --lines=K output the last K lines, instead of the last 10;
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 5) 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
-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
(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

常用的命令展示

head :显示文件的前几行,默认10行
head -n 2 /home/omd/h.txt
==>head -n 3 == head -3 可以直接跟行数
cat h.txt | grep -v "hello" 过滤掉特定字符串,效率低,因为有管道
==>grep -v "hello" h.txt 可以直接跟文件名,效率快
tail: 显示文件最后几行,默认10行
tail -10 /home/omd/h.txt 显示最后10行
tail -f /home/omd/h.txt 实时跟踪文件, 如果文件不存在,则终止
tail -F /home/omd/h.txt 如果文件不存在,会继续尝试
head -30 /home/omd/h.txt | tail -11 /home/omd/h.txt 输出一个文件的20-30行显示文件的前n行
head -n 5 log2014.log输出文件除了最后n行的全部内容
head -n -6 log2014.log从第5行开始显示文件
tail -n +5 log2014.log 【显示文件的全部内容】
tail -n 5 log2014.log 【只显示最后的5行】 根more/less差不多

Linux head/tail命令详解的更多相关文章

  1. 【linux】tail 命令详解

    转自:https://www.cnblogs.com/fps2tao/p/7698224.html Linux命令:显示文件结尾 Head/Tail head 与 tail 就像它的名字一样的浅显易懂 ...

  2. 【转】Linux tail 命令详解

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

  3. linux shell 脚本攻略学习14--head命令详解,tail命令详解

    当要查看上千行的大文件时,我们可不会用cat命令把整个文件内容给打印出来,相反,我们可能只需要看文件的一小部分地内容(例如文件的前十行和后十行),我们也有可能需要打印出来前n行或后n行,也有可能打印除 ...

  4. linux shell 脚本攻略学习 -- head命令详解, tail命令详解

    当要查看上千行的大文件时,我们可不会用cat命令把整个文件内容给打印出来,相反,我们可能只需要看文件的一小部分地内容(例如文件的前十行和后十行),我们也有可能需要打印出来前n行或后n行,也有可能打印除 ...

  5. 【转帖】Linux定时任务Crontab命令详解

    Linux定时任务Crontab命令详解 https://www.cnblogs.com/intval/p/5763929.html 知道有crontab 以及 at 命令 改天仔细学习一下 讲sys ...

  6. Linux定时任务Crontab命令详解_转

    转自:Linux定时任务Crontab命令详解 (部分修改) linux 定时系统则是由 cron (crond) 这个系统服务来控制的.Linux 系统上面原本就有非常多的计划性工作,因此这个系统服 ...

  7. head和tail命令详解

    基础命令学习目录首页 原文链接:https://www.cnblogs.com/amosli/p/3496027.html 当要查看上千行的大文件时,我们可不会用cat命令把整个文件内容给打印出来,相 ...

  8. [转帖]Linux的wget命令详解

    Linux的wget命令详解 来源不明 找到的也是转帖的 https://www.cnblogs.com/cindy-cindy/p/6847502.html Linux wget是一个下载文件的工具 ...

  9. Linux下ps命令详解 Linux下ps命令的详细使用方法

    http://www.jb51.net/LINUXjishu/56578.html Linux下的ps命令比较常用 Linux下ps命令详解Linux上进程有5种状态:1. 运行(正在运行或在运行队列 ...

随机推荐

  1. elasticsearch 导入基础数据并索引之 geo_shape

    我们看到的图形, 实际是由点来完成的, 有2种类型的格子模型可用于地理星座, 默认使用的是geoHash, 还有一种4叉树(quad trees), 也可用于 判断形状与索引的形状关系 1), int ...

  2. MySQL命令行导入导出数据

    参考:http://www.cnblogs.com/xcxc/archive/2013/01/30/2882840.html 这篇文章写得非常好,又简洁,而且深入浅出,排版也非常好看,不会像网上的只是 ...

  3. C#异步,多线程下的HttpContext丢失问题

    1.思路概述 首先让我把大概的一个思路先说一遍吧. 我在一个页面中要同时调用两个接口,而我要给这些接口一些参数:就是我通过HttpContext.Current.Request.QueryString ...

  4. [android] 手机卫士自定义吐司

    继续在之前监听来电的服务AddressService里,添加成员方法MyToast() 获取TextView对象,new出来,构造参数:上下文对象 调用TextView对象的setText()方法,设 ...

  5. iOS原生APP和H5交互-delegate和第三方

    一.原生代码中直接加载页面(拦截) 1.    具体案例 加载本地/网络HTML5作为功能介绍页 2.    代码示例 //本地 -(void)loadLocalPage:(UIWebView*)we ...

  6. 关于在web端运行项目,eclipse报PermGen space错误

    之前在网上也查到过许多解决的方法,但可能因为本人脸黑........也修改过eclipse文件目录中的相关配置文件,并没有得到相应的帮助,因此把自己的改正方法分享下: window-->pref ...

  7. Extjs校验配置项

    Extjsform组件1.Ext.form.Action 配置项:success:执行成功后回调的函数,包括两个参数:form和actionfailure:执行失败后回调的函数,包括两个参数:form ...

  8. 浅谈一致性哈希(My转)

    一致性哈希(Consistent hashing)算法是由 MIT 的Karger 等人与1997年在一篇学术论文(<Consistent hashing and random trees: d ...

  9. CodeForces765A

    A. Neverending competitions time limit per test:2 seconds memory limit per test:512 megabytes input: ...

  10. csharp:获取 DNS、网关、子网掩码、IP

    /// <summary> /// DNS.网关.子网掩码.IP /// 涂聚文 2015 /// </summary> public class IPAddressStrin ...