300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > linux中 使用cat head tail命令显示文件指定行

linux中 使用cat head tail命令显示文件指定行

时间:2023-03-03 09:42:25

相关推荐

linux中 使用cat head tail命令显示文件指定行

小文件可以用cat(也可以用head、tail)

显示文件最后20行:cat err.log | tail -n 20

显示文件前面20行:cat err.log | head -n 20

从第20行开始显示(包含第20行)后面的所有行:cat err.log | tail -n +20

从倒数第20行开始显示(不包含倒数第20行)之前的所有行:cat err.log | head -n -20

显示100行到500行:cat err.log | head -n 500 | tail -n +100

cat err.log | tail -n +100 | head -n 401

sed -n '100,500p' err.log

大文件最好用head、tail

当被查看的文件很大,不要用cat,直接用head,tail

head -n 20 err.log

tail -n 20err.log

显示100行到500行:head -n500 test.txt | tail -n +100

tail -n +100 test.txt| head -n 401

示例

一个很大的文件all.log

看最后20行:tail -f -n20 all.log,也可以简写为:tail -fn20 all.log

看最后20行中的包含error的行(-i表示忽略大小写):tail -f -n20 all.log | grep -i error

给被搜索的关键字加颜色方便查看(默认是红色):tail -f -n20 all.log | grep -i error--color=auto

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。