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. HTTP状态码列表

    经常用的http状态码 1xx消息——请求已被服务器接收,继续处理2xx成功——请求已成功被服务器接收.理解.并接受3xx重定向——需要后续操作才能完成这一请求4xx请求错误——请求含有词法错误或者无 ...

  2. form表单select的选项值选择

    html: <form action=""> <p>选择城市</p> <p> <select name="" ...

  3. 红色警戒3原版V1.00基址大全

    127.0.0.1 servserv.generals.ea.com ===================================1.04 基址变化 00DFBD74=>DFCDF4 ...

  4. 关于Mysql+EF6本地运行和发布没有问题,发布到服务器上出现问题的解决方案

    这个问题折磨了我差不多两天,网上各种方法也找了个遍,但是都没有解决我的问题,后面通过自己仔细分析问题和排查,终于把问题解决了,以下是我的解决问题的步骤,希望能帮到各位,不要再被这些问题坑了 1,项目实 ...

  5. HTML的map-area的使用

    使用背景 在把设置图转成页面的时候,时常会遇到这种情况:一张小图片上有好多个可以点击的小图标,按常规的处理方法是把这一个一个的小图切出来,然后每个加个a标签进行跳转,但是这样会非常的浪费时间,而且会增 ...

  6. XCode 添加自定义framework运行时出现dyld: Library not loaded的解决方法

    XCode添加自定义framework运行时出现dyld: Library not loaded的解决方法 在使用自定义的framework运行时,会出现如下的错误: dyld: Library no ...

  7. Spring系列之——Spring事务以及两大核心IOC和AOP

    1 Spring事务 1.1 Spring事务是什么(百度) 事务是对一系列的数据库操作(比如插入多条数据)进行统一的提交或是回滚操作,如果插入成功,那么一起成功,如果中间一条出现异常,那么回滚之前的 ...

  8. golang chan 发送接收测试数据

    测试代码: package main import (     "fmt"     "time" ) const (     num = 10000000  / ...

  9. Java Web中涉及的编解码

    用户从浏览器发起一个HTTP请求,存在编码的地方是URL.Cookie.Paramiter.服务器端接收到HTTP请求后要解析HTTP协议,其中URL.Cookie和POST表单参数要解码,服务器端可 ...

  10. Java程序中的死锁

    什么是死锁? 死锁是一种特定的程序状态,主要是由于循环依赖导致彼此一直处于等待中,而使得程序陷入僵局,相当尴尬.死锁不仅仅发生在线程之间,而对于资源独占的进程之间同样可能出现死锁.通常来说,我们所说的 ...