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 ~]$

最新文章

  1. 理解RESTful
  2. PEP 8
  3. IE6/7/8中parseInt第一个参数为非法八进制字符串且第二个参数不传时返回值为0
  4. stack, deque 和 queue的对比
  5. cache与SDRAM
  6. Struts2 和 spring mvc的 迭代标签常用属性对比
  7. Codeforces Round #147 (Div. 2)
  8. Swift学习笔记九
  9. ios get airplay name
  10. PHP AOP
  11. 无法修改系统Host的解决办法
  12. C#实现FTP文件夹下载功能【转载】
  13. valuestack(值栈) 和 actioncontext(上下文)
  14. ASP.NET5配置
  15. windows下安装DB2数据库以及使用Aqua Data Studio链接数据库
  16. mysql导出指定字段或指定数据到文件中
  17. TOMCAT闪退。cmd执行startup.bat保错:the CATALINA_HOME environment variable is not defined correctly
  18. Firefox书签同步工具Xmarks
  19. SpringBoot学习笔记(2) Spring Boot的一些配置
  20. vue 中使用jquery

热门文章

  1. 【Python开发】urllib2异常处理
  2. 浅谈Web图像优化
  3. python常用关键字
  4. LCA模板(数剖实现)
  5. PTA(Basic Level)1038.统计同成绩学生
  6. 【转贴】Debian 10 &quot;buster&quot; 正式发布
  7. python函数 -- 作用域,异常处理
  8. opencv学习之读取图像-imread函数
  9. Java switch case 语句
  10. Mysql-Sqlalchemy-增删改查分组等操作