查找某个目录下的所有文本文件

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_44731327/article/details/89446095
用file命令查看所有文件的类型
[root@HFJ ~]# file /var/log/*
/var/log/1-1_CQ_20-21U_RD450_70.51.txt: ASCII text
/var/log/anaconda.ifcfg.log:            ASCII text
/var/log/anaconda.log:                  ASCII text
/var/log/anaconda.program.log:          ASCII English text, with very long lines, with overstriking
/var/log/anaconda.storage.log:          ASCII C++ program text, with very long lines
/var/log/anaconda.syslog:               ASCII English text, with very long lines
/var/log/anaconda.xlog:                 ASCII English text
/var/log/anaconda.yum.log:              ASCII text
/var/log/ASCII:                         empty
/var/log/ASCII:ascii:                   empty
....
过滤以冒号:分隔的最后一列中的ASCII行


  [root@HFJ ~]# file /var/log/*|awk -F ":" '$NF~/ASCII/{print $0}'
/var/log/1-1_CQ_20-21U_RD450_70.51.txt: ASCII text
/var/log/anaconda.ifcfg.log:            ASCII text
/var/log/anaconda.log:                  ASCII text
/var/log/anaconda.program.log:          ASCII English text, with very long lines, with overstriking
/var/log/anaconda.storage.log:          ASCII C++ program text, with very long lines
/var/log/anaconda.syslog:               ASCII English text, with very long lines
/var/log/anaconda.xlog:                 ASCII English text
/var/log/anaconda.yum.log:              ASCII text
/var/log/boot.log:                      ASCII English text, with CRLF, CR, LF line terminators, with escape sequences
awk -F ":" '$NF~/ASCII/{print $0}'
$NF表示最后一个字段,~表示模糊匹配
$NF~/ASCII/:查找$NF字段中含有ASCII的行
展开阅读全文

没有更多推荐了,返回首页