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套接口编程文章

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由jackieluo发表于云+社区专栏 TCP客户端-服务器典型事件 下图是TCP客户端与服务器之间交互的一系列典型事件时间表: 首先启 ...

  2. SpringMVC源码阅读:视图解析器

    1.前言 SpringMVC是目前J2EE平台的主流Web框架,不熟悉的园友可以看SpringMVC源码阅读入门,它交代了SpringMVC的基础知识和源码阅读的技巧 本文将通过源码(基于Spring ...

  3. CocoaPods管理第三方

    之前听伟哥说用CocoaPods做第三方库的管理很方便,今天看了下自己做了下感觉确实不错.下面开始,Let's go!! 1.安装CocoaPods之前,先确保本地有Ruby环境,因为CocoaPod ...

  4. iOS开源项目周报0330

    由OpenDigg 出品的iOS开源项目周报第十四期来啦.我们的iOS开源周报集合了OpenDigg一周来新收录的优质的iOS开源项目,方便iOS开发人员便捷的找到自己需要的项目工具等. FengNi ...

  5. SpringBoot配置——@PropertySource、@ImportResource、@Bean

    @PropertySource:加载指定的配置文件 package com.hoje.springboot.bean; import org.springframework.beans.factory ...

  6. JSP学习笔记(4)-Javabean

    按照sun公司的定义,Javabean是一个可重复使用的软件组件,实际上Javabean是一种Java类,通过封装属性和方法成为具有某种功能或处理某个业务的对象,简称Bean,Javabean基于ja ...

  7. Linux学习1-创建虚拟机

    VMware安装非常简单,使用默认安装就可以,VMware尽量使用低版本的软件,这样可以降低系统的消耗 1.新建一个虚拟机 2.直接选择默认的典型安装         3.选择安装来源:此处选择最后一 ...

  8. future3.2 Tomcat启动时错误:Cannot rename original file to ...

    其日志中第一个警告如下: 警告: Unexpected exception resolving reference java.io.IOException: Cannot rename origina ...

  9. 洛谷P4360 [CEOI2004]锯木厂选址(dp 斜率优化)

    题意 题目链接 Sol 枚举第二个球放的位置,用前缀和推一波之后发现可以斜率优化 // luogu-judger-enable-o2 #include<bits/stdc++.h> #de ...

  10. bootstrapValidator验证中Maximum call stack size exceeded

    Tip1:如果表单不是通过Bootstrap构建(即元素包含表单项且关联的label没有form-group类),可能会看到错误Uncaught RangeError: Maximum call st ...