linux 查看文件开头几行、末尾几行、中间几行

查看整个文件

cat [filename]

例如:查看/home/user/test.txt

cat /home/user/test.txt

查看开头几行

head -n [rows] [filename]

例如:查看/home/user/test.txt的前20行

head -n 20 /home/user/test.txt

查看末尾几行

tail -n [rows] [filename]

例如:查看/home/user/test.txt的最后10行

tail -n 10 /home/user/test.txt

查看中间几行

方法一:

cat [filename]| head -n [endRow] | tail -n +[beginRow]

例如:查看/home/user/test.txt的10~20行

cat /home/user/test.txt| head -n 20 | tail -n +10 

head -n 20 表示前20行

tail -n 10 表示后10行

tail -n +10 表示第10行之后的

方法二:

sed -n '[begin],[end]p' [filename]

例如:查看/home/user/test.txt的10~20行

sed -n '10,20p' /home/user/test.txt

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值