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. TCP三次握手/四次挥手

    TCP 三次握手 TCP 连接是通过三次握手进行初始化的.三次握手的目的是同步连接双方的序列号和确认号并交换 TCP 窗口大小信息.以下步骤概述了通常情况下客户端计算机联系服务器计算机的过程: 1.  ...

  2. 重置Root用户密码

    在忘记root用户密码是用于重置root用户密码: 1.开机按e. 2.在linux16开头的一行的末尾添加rd.break,按ctrl+x. 3.依次执行命令: mount -o remount,r ...

  3. Shell脚本编写2------有关变量

    shell脚本中变量定义方式十分简单,直接将值赋值给变量较好例如 :name="tuanzhang"注意,变量名和等号之间不能有空格,这可能和你熟悉的所有编程语言都不一样.变量命名 ...

  4. Message小结(一)

      一.消息版本 为了区别消息的结构和寻址机制,W3C定制了SOAP1.1和SOAP1.2定义消息的结构,WS-Addressing 2004和WS-Addressing 1.0定义消息的寻址机制. ...

  5. rabbitmq-channel方法介绍

    先介绍rabbmitmq的几个方法: // 声明一个队列 -// queue 队列名称 // durable 为true时server重启队列不会消失 (是否持久化) // exclusive 队列是 ...

  6. Javascript Madness: Mouse Events

    http://unixpapa.com/js/mouse.html Javascript Madness: Mouse Events Jan WolterAug 12, 2011 Note: I ha ...

  7. Eureka Server项目启动报错处理

    Eureka Server项目启动报错处理 Eureka是一个服务发现组件,提供服务注册.发现等注册中心功能,使用spring boot启动eureka应用时出现报错: 20:36:17.646 [r ...

  8. Mac下显示和隐藏隐藏文件的命令

    打开终端,输入: 1.defaults write com.apple.finder AppleShowAllFiles -bool true 此命令显示隐藏文件defaults write com. ...

  9. IntelliJ IDEA创建spring-boot项目

    开发环境: jdk版本:JDK8 maven版本:maven-3.5.2 开发工具:Itellij IDEA 2017.1 前提条件:已安装以上软件并配置好jdk和maven的环境变量 创建步骤: 点 ...

  10. Servlet自动注入Spring容器中的Bean解决方法

    很多情况在进行Web开发的时候需要自己手写Servlet来完成某些功能,而servlet有需要注入Spring容器中的某些bean,这是每次都要手动获取比较麻烦,这里有一个解决方案,只需要写一个ser ...