在bash中使用正则表达式打印文件名

问题描述 投票:0回答:1

用以下命令打印出*.crt, *.key, *.csr文件

for i in $(find . -maxdepth 1 -mtime +90 -type f -ls | egrep "crt|key|csr" | awk '{print $NF}'); do echo "FILE: $i" done

我必须检查*.crt文件,找出那是什么类型的证书,所以我使用以下命令打印出我需要的信息

openssl x509 -in $i -issuer|head -1

如何忽略其他文件并仅对我循环中的openssl文件执行crt

linux bash
1个回答
1
投票
while IFS= read -rd '' file; do
    #do something with crt files
    if [[ $file = *.crt ]]; then
        echo "check cert"
    fi
    #do something with all files
    echo "$file"
done < <(find . -maxdepth 1 -type f -mtime +90 \( -name "*.crt" -o -name "*.key" -o -name "*.csr" \) -print0)
© www.soinside.com 2019 - 2024. All rights reserved.