1.tail

tail命令用途是按照要求将指定的文件的最后部分输出到标准设备,

一般是终端,通俗来讲,就是把某个档案文件的最后几行显示到终端上,

如果该档案有更新,tail会自动刷新,确保你看到最新的档案内容。

tail命令语法

tail   [ -f ]   [ -c Number | -n Number | -m Number| -b Number | -k Number ]    [ File ]

参数说明:

-f 该参数用于监视File文件增长。

-c Number 从 Number 字节位置读取指定文件

-n Number 从 Number 行位置读取指定文件。

-m Number 从 Number 多字节字符位置读取指定文件,比如你的文件如果包含中文字,如果指定-c参数,可能导致截断,但使用-m则会避免该问题。

-b Number 从 Number 表示的512字节块位置读取指定文件。

-k Number 从 Number 表示的1KB块位置读取指定文件。

File 指定操作的目标文件名

上述命令中,都涉及到number,如果不指定,默认显示10行。Number前面可使用正负号,表示该偏移从顶部还是从尾部开始计算。

tail --help
Usage: tail [OPTION]... [FILE]...
Print the last lines of each FILE to standard output.
With more than one FILE, precede each with a header giving the file name.
With no FILE, or when FILE is -, read standard input. Mandatory arguments to long options are mandatory for short options too.
-c, --bytes=K output the last K bytes; or use -c +K to output
bytes starting with the Kth of each file
-f, --follow[={name|descriptor}]
output appended data as the file grows;
an absent option argument means 'descriptor'
-F same as --follow=name --retry
-n, --lines=K output the last K lines, instead of the last ;
or use -n +K to output starting with the Kth
--max-unchanged-stats=N
with --follow=name, reopen a FILE which has not
changed size after N (default ) 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 if it is inaccessible
-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 If the first character of K (the number of bytes or lines) is a '+',
print beginning with the Kth item from the start of each file, otherwise,
print the last K items in the file. K may have a multiplier suffix:
b , kB , K , MB *, M *,
GB **, G **, and so on for T, P, E, Z, Y. With --follow (-f), tail defaults to following the file descriptor, which
means that even if a tail'ed file is renamed, tail will continue to track
its end. This default behavior is not desirable when you really want to
track the actual name of the file, not the file descriptor (e.g., log
rotation). Use --follow=name in that case. That causes tail to track the
named file in a way that accommodates renaming, removal and creation.

tail命令用法示例

1、tail -f filename

说明:监视filename文件的尾部内容(默认10行,相当于添加参数 -n 10),刷新显示在屏幕上。退出,按下CTRL+C。

2、tail -n 20 filename

说明:显示filename最后20行。

3、tail -n +10 filename

说明:显示filename前面10行以后的。(展示不全)

2.head

head命令用于显示文件文字区块

1、格式

  head 【参数】【文件】

2、参数

  -q 隐藏文件名(默认)

  -v 显示文件名

  -c<字节> 显示字节数

  -n<行数> 显示的行数(默认)

cat test.sh==》
No Name Mark Percent
tom 69 91
jack 71 87
alex 68 98

[centos@s203 ~]$ head -n  test.sh
No Name Mark Percent
tom
jack
alex
[centos@s203 ~]$ head -n test.sh
No Name Mark Percent
tom
[centos@s203 ~]$ head -n -v test.sh
==> test.sh <==
No Name Mark Percent
tom
[centos@s203 ~]$ head -n -v -q test.sh
No Name Mark Percent
tom
[centos@s203 ~]$ head -n -v -q -c test.sh
No [centos@s203 ~]$
[centos@s203 ~]$
[centos@s203 ~]$
[centos@s203 ~]$ head -v -q -c test.sh
No [centos@s203 ~]$ head -n -v -q -c test.sh
No Name Mark Percent
tom
jack
alex
[centos@s203 ~]$ head -n -v -q -c test.sh
No Name Ma[centos@s203 ~]$

head&tail命令的更多相关文章

  1. tail命令详解

    搜索 纠正错误  添加实例 tail 在屏幕上显示指定文件的末尾若干行 补充说明 tail命令 用于输入文件中的尾部内容.tail命令默认在屏幕上显示指定文件的末尾10行.如果给定的文件不止一个,则在 ...

  2. Linux命令详解之—tail命令

    tail命令也是一个非常常用的文件查看类的命令,今天就为大家介绍下Linux tail命令的用法. 更多Linux命令详情请看:Linux命令速查手册 Linux tail命令主要用来从指定点开始将文 ...

  3. 每天一个 Linux 命令(15):tail 命令

    tail 命令从指定点开始将文件写到标准输出.使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail -f filename会把filename里最尾部的内容显示在屏幕上,并且不但刷新, ...

  4. Linux head和tail命令

    200 ? "200px" : this.width)!important;} --> 介绍 head和tail是一组想对应的命令,默认分别显示文件的开头和末尾10行记录. ...

  5. 每天一个linux命令(15):tail 命令

    tail 命令从指定点开始将文件写到标准输出.使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail -f filename会把filename里最尾部的内容显示在屏幕上,并且不但刷新, ...

  6. tail 命令 查看Tomcat目录下日志的最后几行的方法

    工作中需要查看日志信息,进行排错,但是面对上万行的错误日志,从头开始往后看,比较浪费时间,所有使用tail命令会节省不少时间. 1.命令   tail  - n  opt/tomcat/logs/ca ...

  7. 【转载】linux tail命令的使用方法详解

    本文介绍Linux下tail命令的使用方法.linux tail命令用途是依照要求将指定的文件的最后部分输出到标准设备,通常是终端,通俗讲来,就是把某个档案文件的最后几行显示到终端上,假设该档案有更新 ...

  8. 每天一个linux命令(13):tail 命令

    tail 命令从指定点开始将文件写到标准输出.使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail -f filename会把filename里最尾部的内容显示在屏幕上,并且不但刷新, ...

  9. linux tail命令的使用方法详解(转)

    本文介绍Linux下tail命令的使用方法.linux tail命令用途是依照要求将指定的文件的最后部分输出到标准设备,通常是终端,通俗讲来,就是把某个档案文件的最后几行显示到终端上,假设该档案有更新 ...

  10. 菜鸟学Linux命令:tail命令 查看日志

    tail 命令用于显示指定文件末尾内容,不指定文件时,作为输入信息进行处理. tail命令常用来查看日志文件.使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail -f filenam ...

随机推荐

  1. Android开发 互相调用模式之导出Jar包、扩展MainActivity、Java主导

    首先讲导出Jar包,在以前都是用这种方法,但是现在官方不推荐使用此方法,官方推荐导出Aar包 (1)首先创建一个Android空工程 注意:这里选择API 16,因为Unity支持的最低是API 16 ...

  2. comodo firewall 科莫多离线安装

    comodo firewall是什么?他配有HIPS,配置好规则就可以比杀软强不是一个两个档次,但是新手不建议使用. 注意:不用使用疯狂模式后锁屏,不然系统都打不开. 下载地址: https://do ...

  3. 通道的分离与合并,ROI,

    通道的分离与合并 class Program { static void Main(String[] args) { Mat img = CvInvoke.Imread(@"C:\Users ...

  4. Luogu P5068 [Ynoi2015]我回来了

    题目 Ynoi难得的水题. 首先我们可以\(O(n^2)\)地求出任意两点之间的距离. 然后我们可以\(O(n^3)\)地求出对于任意一个点\(u\),跟它距离\(\le d\)的点的集合. 然后对于 ...

  5. 2018.08.14【2018提高组】模拟A组 比赛总结

    题解 这次的A组难得得水. T1 这题我一看,就想起了GDOI的一道题--密码锁 \(O(n)\)算法--差分 于是乎兴奋地发现这道题可以用差分来解. 设\(f_i=a_i-a_{i-1}\). 然后 ...

  6. MyBatis的foreach查询(List、Array、Map)

    mybatis 中 foreach collection的三种用法 foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合. foreach元素的属性主要有 item,index ...

  7. 哈希表(Hash table)

  8. 权限(rwx)对于目录与文件的意义

    1-权限对于目录的意义 首先要明白的是目录主要的内容是记录文件名列表和子目录列表,而不是实际存放数据的地方. r权限:拥有此权限表示可以读取目录结构列表,也就是说可以查看目录下的文件名和子目录名,注意 ...

  9. 帝国cms 通过tags给产品或者新闻进行分类

    1.增加TAGS分类 先找到栏目== >TAGS管理 == > 管理TAGS分类 == >增加分类 2.增加相关的tag标签,也要选好TAGS分类 3.增加自定义标签模板 具体怎么写 ...

  10. 基于Zabbix 3.2.6版本的Discovery

    作用:用于发现某IP网段内存活并且满足一定条件的主机,发现后进行加入到zabbix server进行监控. 操作步骤: 创建[自动发现规则] 为新建的自动发现规则创建[Action]   操作步骤图文 ...