Linux head/tail命令详解
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命令详解的更多相关文章
- 【linux】tail 命令详解
转自:https://www.cnblogs.com/fps2tao/p/7698224.html Linux命令:显示文件结尾 Head/Tail head 与 tail 就像它的名字一样的浅显易懂 ...
- 【转】Linux tail 命令详解
Linux tail 命令详解 http://www.2cto.com/os/201111/110143.html
- linux shell 脚本攻略学习14--head命令详解,tail命令详解
当要查看上千行的大文件时,我们可不会用cat命令把整个文件内容给打印出来,相反,我们可能只需要看文件的一小部分地内容(例如文件的前十行和后十行),我们也有可能需要打印出来前n行或后n行,也有可能打印除 ...
- linux shell 脚本攻略学习 -- head命令详解, tail命令详解
当要查看上千行的大文件时,我们可不会用cat命令把整个文件内容给打印出来,相反,我们可能只需要看文件的一小部分地内容(例如文件的前十行和后十行),我们也有可能需要打印出来前n行或后n行,也有可能打印除 ...
- 【转帖】Linux定时任务Crontab命令详解
Linux定时任务Crontab命令详解 https://www.cnblogs.com/intval/p/5763929.html 知道有crontab 以及 at 命令 改天仔细学习一下 讲sys ...
- Linux定时任务Crontab命令详解_转
转自:Linux定时任务Crontab命令详解 (部分修改) linux 定时系统则是由 cron (crond) 这个系统服务来控制的.Linux 系统上面原本就有非常多的计划性工作,因此这个系统服 ...
- head和tail命令详解
基础命令学习目录首页 原文链接:https://www.cnblogs.com/amosli/p/3496027.html 当要查看上千行的大文件时,我们可不会用cat命令把整个文件内容给打印出来,相 ...
- [转帖]Linux的wget命令详解
Linux的wget命令详解 来源不明 找到的也是转帖的 https://www.cnblogs.com/cindy-cindy/p/6847502.html Linux wget是一个下载文件的工具 ...
- Linux下ps命令详解 Linux下ps命令的详细使用方法
http://www.jb51.net/LINUXjishu/56578.html Linux下的ps命令比较常用 Linux下ps命令详解Linux上进程有5种状态:1. 运行(正在运行或在运行队列 ...
随机推荐
- [CQOI 2018]异或序列&[Codeforces 617E]XOR and Favorite Number
Description 题库链接1 题库链接2 已知一个长度为 \(n\) 的整数数列 \(a_1,a_2,\cdots,a_n\) ,给定查询参数 \(l,r\) ,问在 \([l,r]\) 区间内 ...
- bind9配置转发服务
修改bind主配置文件 $ vi /etc/named.conf//// named.conf//// Provided by Red Hat bind package to configure th ...
- HttpContext概念讲解
一:HttpContext理论知识: 1:HttpContext类它对Request.Respose.Server等等都进行了封装,并保证在整个请求周期内都可以随时随地的调用:为继承 IHttpMod ...
- 边框圆角Css
.box{ background:grey; //灰色背景 height:50px; //高500像素 width:200px; //宽200像素 border-top-left-radius:15p ...
- Spark你需要知道这些
谈到 Spark,我们总是强调它比 Hadoop 更高效.为什么它可以更高效呢?是因为它优先使用内存存储?还是因为它拥有比 MapReduce 更简单高效的计算模型? 与 Hadoop 作业的区别 我 ...
- SpringBoot(五) Web Applications: MVC
统一异常处理 SpringBoot的默认映射 /error 码云: commit: 统一异常处理+返回JSON格式+favicon.ico 文档: 28.1.11 Error Handling 参考 ...
- 商城项目,java返回json数据,报错406
前言: 项目结构为maven,搭建好架构,整合ssm,进行测试, 从数据库中查询数据,返回json数据,结果报错406 问题: 解决: 1,确定项目中json包是否存在(极大可能出于此) 2,处理器适 ...
- 量子猴排(Quantum Bogo sort)
排序原理 原理很简单,如果数组不是有序的,就洗一次牌,直至数组有序为止 时间复杂度 最佳情况O(n),平均情况O(n×n!) 代码如下: import java.util.Random; public ...
- Unity3d之MonoBehavior自带方法的执行顺序
首先贴一张图(从其他地方摘录的,不记得出处,如果有小伙伴知道可以评论留言) 看了以后脑子有个大概的概念,可还是一知半解的感觉(接触Unity也有2年之久,却从来没想过弄清楚心中这团迷雾,总是囫囵吞枣用 ...
- BootStrap-select 插件的使用
这是一款下拉框多选的插件,非常的抢到,什么样式都是有的:首先去参看一下官网的信息,详细介绍是怎么使用的: 相关官网网址: https://silviomoreto.github.io/bootstr ...