Linux中的head和tail命令

#######head、tail命令###########
head命令
用途:查看文件开头的一部分内容(默认为10行)
格式:head -n number 文件名
格式:head -数字  文件名
tail命令
用途:查看文件结尾的少部分内容(默认为10行)
格式:tail  -n  number 文件名
格式:tail  -数字   文件名           
          tail  -f  文件名  = tailf

[root@hp lianxi]# cat test 
1a
2b
3c
4d
5e
6f
7g
8h
9i
10j
11k
12l
13m

[root@hp lianxi]# head -n 2 test
1a
2b
[root@hp lianxi]# head  -2 test
1a
2b
[root@hp lianxi]# 

[root@localhost lianxi]# tail -n +10 test
10j
11k
12l
13m
[root@localhost lianxi]# tail -n 2 test
12l
13m

#查看文件的5到7行
[root@localhost lianxi]# head -n 7 test | tail -n 3 

#管道符号:
     上一条命令的输出,成为下一条命令的输入

格式:tail  -n 数字 文件名
数字:数字前有 +(加号),从文件开头指定的单元      数开始输出;数字前有 -(减号),从文件末尾指定的单元 数开始输出;没有 +或 -,从文件末尾指定的单元 数开始输出。
例如:
tail -n +3 /etc/passwd 从第三行开始显示
tail -n -3  /etc/passwd 显示最后三行

head -n 3 /etc/passwd  显示前三行
head -n -3 /etc/passwd 显示倒数第三行之前

#tail -f 实时监控文件追加信息 (按ctrl+c终止)
[root@localhost log]# pwd
/var/log
[root@localhost log]# tail -f messages 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值