taild linux语言,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差不多

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值