Liunx运维(三)-文件过滤及内容编辑处理 (2)

Liunx运维(三)-文件过滤及内容编辑处理

 2、head -3 test3.txt #显示文件的前n行

Liunx运维(三)-文件过滤及内容编辑处理

 3、head -c 10 /etc/passwd #显示文件前10个字节

 

Liunx运维(三)-文件过滤及内容编辑处理

 4、head -1 /etc/passwd /etc/gshadow #显示多个文件头部内容

Liunx运维(三)-文件过滤及内容编辑处理

 

六、tail:显示文件内部尾部

1、tail /etc/passwd #默认显示尾部10行

Liunx运维(三)-文件过滤及内容编辑处理

 2、tail -n 5 /etc/passwd #显示尾部5行

Liunx运维(三)-文件过滤及内容编辑处理

 3、tail -5 /etc/passwd #显示尾部5行,简洁写法

Liunx运维(三)-文件过滤及内容编辑处理

 4、tail -f /opt/tools/elasticsearch-7.10.1/logs/elasticsearch.log #实时监控文件变化

Liunx运维(三)-文件过滤及内容编辑处理

 5、tail -F 123.txt #实时监控,文件不存在报错,但是会等待文件生成不退出命令

Liunx运维(三)-文件过滤及内容编辑处理

 

七、tailf:跟踪日志文件

1、tailf /opt/tools/elasticsearch-7.10.1/logs/elasticsearch.log #默认跟踪10行命令

Liunx运维(三)-文件过滤及内容编辑处理

2、tailf -5 /opt/tools/elasticsearch-7.10.1/logs/elasticsearch.log #指定跟踪最后n行

Liunx运维(三)-文件过滤及内容编辑处理

 

 八、cut:从文本中提取一段文字并输出

1、cut -b 3 test4.txt #只输出第3个字符

Liunx运维(三)-文件过滤及内容编辑处理

 2、cut -b 3-5,10 test4.txt #支持-的写法,多个定位用逗号分割

Liunx运维(三)-文件过滤及内容编辑处理

 3、cut -b -5 test4.txt #表示从第1个字符到第5个字符

Liunx运维(三)-文件过滤及内容编辑处理

 4、cut -b 6- test4.txt #表示从第6个字符到尾部

Liunx运维(三)-文件过滤及内容编辑处理

 5、cut -c 3-5 test4.txt #以字符分割,中文也显示正常

Liunx运维(三)-文件过滤及内容编辑处理

 6、cut -d : -f 1 /etc/passwd #指定以:作为分割显示

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zygwpx.html