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 10 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 outputbytes 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 10;or use -n +K to output starting with the Kth--max-unchanged-stats=Nwith --follow=name, reopen a FILE which has notchanged size after N (default 5) iterationsto 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 atleast once every N seconds-v, --verbose            always output headers giving file names--help     display this help and exit--version  output version information and exitIf 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 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024,
GB 1000*1000*1000, G 1024*1024*1024, 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 10 test.sh
No Name Mark Percent
tom 69 91
jack 71 87
alex 68 98
[centos@s203 ~]$ head -n 2 test.sh
No Name Mark Percent
tom 69 91
[centos@s203 ~]$ head -n 2 -v test.sh
==> test.sh <==
No Name Mark Percent
tom 69 91
[centos@s203 ~]$ head -n 2 -v -q test.sh
No Name Mark Percent
tom 69 91
[centos@s203 ~]$ head -n 2 -v -q -c 3 test.sh
No [centos@s203 ~]$
[centos@s203 ~]$
[centos@s203 ~]$
[centos@s203 ~]$ head  -v -q -c 3 test.sh
No [centos@s203 ~]$ head -n 2 -v -q -c 100 test.sh
No Name Mark Percent
tom 69 91
jack 71 87
alex 68 98
[centos@s203 ~]$ head -n 2 -v -q -c 10 test.sh
No Name Ma[centos@s203 ~]$

转载于:https://www.cnblogs.com/wqbin/p/10932587.html

headtail命令相关推荐

  1. Linux headtail命令

    head与tail都是以行为单位进行数据选取的,head是取出前面,tail是取出后面的. head(取出前面几行) 1.命令格式: head [参数]... [文件]... 2.命令参数: -q 隐 ...

  2. Linux命令(8):headtail命令

     head与tail都是以行为单位进行数据选取的,head是取出前面,tail是取出后面的. head(取出前面几行) 命令格式: head [参数]... [文件]... 命令参数: -q 隐藏文件 ...

  3. linux命令headtail

    一.head 语法 head [-n -k ]... [FILE]... //k是数字 默认是显示开头前10行. head /etc/passwd 显示开头前5行 head -5 /etc/passw ...

  4. linux tee 重定向_快乐的linux命令行-重定向

    整理自<快乐的linux命令行一书>. linux系统版本: Ubuntu 17.04 本章,我们将介绍命令行最酷的特性,叫做I/O重定向,通过这个工具,可以重定向命令的输入输出,命令的输 ...

  5. Kubectl 常用命令, 开发人员常用k8s命令

    Kubectl 常用命令: 什么是常用,我用的,就是常用的

  6. ECS(Linux)连接RDS,使用命令行方式连接实例

    使用命令行方式连接实例 通过命令行连接RDS MySQL数据库,连接方式如下: mysql -h<连接地址> -P<端口> -u<用户名> -p -D<数据库 ...

  7. 设置普通用户执行docker命令,执行docker命令无需输入密码或者切换root用户

    每次执行docker命令都要输入密码或者切换root用户,非常不方便,尤其是在shell脚本中就更麻烦了,一起来解决这个问题: 1. 创建名为docker的组,如果之前已经有该组就会提示已存在: su ...

  8. 从命令行到IDE,版本管理工具Git详解(远程仓库创建+命令行讲解+IDEA集成使用)

    首先,Git已经并不只是GitHub,而是所有基于Git的平台,只要在你的电脑上面下载了Git,你就可以通过Git去管理"基于Git的平台"上的代码,常用的平台有GitHub.Gi ...

  9. 作为一个java程序员,常用的linux命令(越攒越多)

    本篇记录我在工作中不断遇到的常用的linux命令,并进行总结,时常更新! 1. 升级服务时先停止服务,然后进行替换 linux中杀进程时候,如果你是知道它所占用的端口号的话,可以通过 netstat ...

  10. docker上你必须会的那些命令

    一.基础类 查看docker信息 # 查看docker版本 docker version # 显示docker系统的信息 docker info # 日志信息 docker logs # 故障检查 s ...

最新文章

  1. 演练:创建和使用静态库 (C++)
  2. 《Objective-C基础教程》第二章 对C的扩展
  3. CentOS 7 Linux 的初始化系统(系统服务管理和控制程序/Init System) -- systemd 详解
  4. 最有价值的100句话
  5. struts2面试整理
  6. 【ambari】Ambari Rest api 使用
  7. html 自动获取屏幕分辨率,HTML5教程 如何获取手机屏幕分辨率和浏览器分辨率
  8. 自学python教程免费python教程视频
  9. 安卓中关于图片的类型
  10. micropython esp8266教程_ESP8266 Micropython – 连接大学Wi-Fi(WPA2 Enterprise PEAP)
  11. 2020年测绘资质申请流程
  12. 人工智能(1)-样本空间、假设空间、版本空间
  13. 在前端中清除IE浏览器缓存问题
  14. 如何优雅的用MarkDown编写一份简历
  15. oracle出现“无法为表空间 XX 中的段创建 INITIAL 区”错误
  16. 一个可以绑定多个天翼云网盘的目录列表程序,支持视频播放
  17. AirDisk产品Q3C和T2硬盘不认的时候,一般就三种原因
  18. 给正在注册或即将注册个体工商户营业执照的你
  19. js下载文件、音频、视频的方式
  20. 小孩在平板上用计算机,小孩子使用平板电脑好不好

热门文章

  1. 开机一直转圈_天气转凉,电脑早上开机也需要预热了吗?
  2. 算数基本定理 + 例题
  3. Linux chapter 3
  4. 添加谷歌账户显示与服务器,解决添加google同步帐户出错竟然可以这般简单!
  5. 阶段3 2.Spring_03.Spring的 IOC 和 DI_4 ApplicationContext的三个实现类
  6. ARC 101E.Ribbons on Tree(容斥 DP 树形背包)
  7. 详解C# 匿名对象(匿名类型)、var、动态类型 dynamic
  8. 每一个写博客的程序猿,都应该被温柔对待
  9. 【NOIP 模拟赛】Evensgn 剪树枝 树形dp
  10. Spark系列(三)SparkContext分析